Question

I have a table with name buildings and I want to drop it because i forgot a column. In cmd I go to the folder and type "sqlite3" then ".tables" and nothing shows me. why that? and what can i do?

Was it helpful?

Solution 2

You should avoid directly manipulating the database and use migrations instead. If you forgot to add a column then you should create a new migration using add_column to add the column to the table.

Alternativly if the previous migration was the one that created the table with the missing column and you've not distributed this migration yet you can do rake db:rollback, editing the migration and run rake db:migrate again.

Your lack of tables when running the sqlite command is most likely because you forgot to specify the sqlite file to load: sqlite3 <db_name>

OTHER TIPS

Proper way to drop database table is to write migration for it.

Migrations are a convenient way for you to alter your database in a structured and organized manner. You could edit fragments of SQL by hand but you would then be responsible for telling other developers that they need to go and run them. You’d also have to keep track of which changes need to be run against the production machines next time you deploy.

Active Record tracks which migrations have already been run so all you have to do is update your source and run rake db:migrate. Active Record will work out which migrations should be run. It will also update your db/schema.rb file to match the structure of your database.

Source: http://guides.rubyonrails.org/migrations.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top