Ruby on Rails: adding columns to existing database

前端 未结 7 713
Happy的楠姐
Happy的楠姐 2021-01-30 07:49

I\'m getting an error:

SQLite3::SQLException: no such column: ideas.list_id: 
SELECT \"ideas\".* FROM \"ideas\"  
WHERE \"ideas\".\"list_id\" = 2
相关标签:
7条回答
  • 2021-01-30 08:18

    As Speransky suggested, you should never modify old migration files. Rather you should create a new migration that adds the desired column. For instance, in this case you would run the following command in your app to create the new migration:

    rails generate migration AddListIdColumnToIdeas list_id:integer
    

    And Rails would generate the migration file automatically and the only thing left to do is run rake db:migrate.

    If you insist on modifying the old migration file, you can add the column as you did and run the following:

    rake db:drop
    rake db:create
    rake db:migrate
    

    Which will destroy your current database, create a new one and run all the migrations (which will include your new column).

    0 讨论(0)
提交回复
热议问题