Before updating scaffolding from new db schema
We need to create our own class to override the generation of the fields themselves.
To do this we need to extend two classes, namely, Scaffold Sandbox and Scaffold Generator.
To do this, we'll create a folder under [RAILS_HOME]/lib/rails_generator/generators/components called table_scaffold/.
Then, copy the templates/ folder from the original scaffold directory into the new one.
There are a few ways to workaround this error; each has some pros and cons, depending on what you need.
This approach will create a new database each time you give a new database name in the connection string and leave the old database unused.
Now you can test view the scaffolded pages and won’t see the error anymore.
The good thing about this approach is you just modify the exact table representing the model that you’re changing, and leave the rest of the database intact.
First, you need to bring up “Package Manager Console”, Tools – From now on, each time you modify the model and re-run the scaffolding, you need to run the Add-Migration, and Update-Database commands.
In our example above, after adding Description and Category, we run those commands as follows.
With the second workaround, you still need to remember to modify the connection string each time the model is changed.