ruby-on-rails – 迁移后删除rails模型
发布时间:2020-12-16 19:15:24 所属栏目:百科 来源:网络整理
导读:对我来说,创建模型,运行迁移,销毁它,再次创建相同的模型报告SQL异常似乎很奇怪: project|master ? rails g model name name invoke active_record create db/migrate/20130417185814_create_names.rb create app/models/name.rbproject|master? ? rake db:m
对我来说,创建模型,运行迁移,销毁它,再次创建相同的模型报告SQL异常似乎很奇怪:
project|master ? rails g model name name invoke active_record create db/migrate/20130417185814_create_names.rb create app/models/name.rb project|master? ? rake db:migrate == CreateNames: migrating ==================================================== -- create_table(:names) -> 0.0020s == CreateNames: migrated (0.0021s) =========================================== project|master? ? rails d model name invoke active_record remove db/migrate/20130417185814_create_names.rb remove app/models/name.rb project|master? ? rake db:migrate project|master? ? rails g model name test invoke active_record create db/migrate/20130417185845_create_names.rb create app/models/name.rb project|master? ? rake db:migrate == CreateNames: migrating ==================================================== -- create_table(:names) rake aborted! An error has occurred,this and all later migrations canceled: SQLite3::SQLException: table "names" already exists: CREATE TABLE "names" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"test" varchar(255),"created_at" datetime NOT NULL,"updated_at" datetime NOT NULL) /path/project/db/migrate/20130417185845_create_names.rb:3:in `change' -- create_table("names",{:force=>true}) -> 0.0100s -- initialize_schema_migrations_table() -> 0.0025s -- assume_migrated_upto_version(20130417185814,["/path/project/db/migrate"]) -> 0.0010s You have 1 pending migrations: 20130417185845 CreateNames Run `rake db:migrate` to update your database then try again. 也许,我做错了什么?迁移具有删除表的代码 – 它是否仅用于回滚? 解 删除模型和数据库表并生成一个新表非常简单: >创建模型:rails g model用户名 解决方法rails d model name 这只是删除模型而不是您运行的迁移(在数据库中创建了表). 如果要删除模型和表,则必须执行以下操作 rake db:rollback rails d model name (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |