Remove rails model after migration

后端 未结 3 1462
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 05:38

It seems strange to me, that creation of model, running migration, destroying it, and creating again same model reports SQL exception:

project|master ⇒ rails g m         


        
相关标签:
3条回答
  • 2021-02-06 06:03
    rails d model name 
    

    This just deletes the model and not the migration you have run (which created the table in the database).

    If you want to delete both the model and the tables, you will have to do the following

    rake db:rollback 
    rails d model name
    
    0 讨论(0)
  • 2021-02-06 06:12

    You deleted the model–that's a different operation than rolling back a migration.

    Destroying a model does precisely, and only, that; it has nothing to do with migrations.

    0 讨论(0)
  • 2021-02-06 06:14

    according to your migration error there must be something wrong with the migration files, moreover the one which referring to create names table.

    please look at this file, at your change method.

    the change method in a migration file is supposed to execute a DB code, that DB code can do some operations on the DB, and that same code on the change supposed to be right to do the rolling back.

    if you want to separate between the two you should put the code on the up method which will perform operations on the DB, and on the down method the opposite rolling operations.

    i would suggest that you delete all the files on the migration including the one that cause the problem, and write them correct.

    if you need help please post your migration file.

    please also take a look at the guides: http://guides.rubyonrails.org/migrations.html

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