我有一个现有的rails项目,我正在使用postgres数据库,并在成功执行bundle exec rake db:migrate命令后,当我要执行bundle exec rake db:seed命令时,它会抛出以下错误。< / p> 耙子流产了! PG :: DuplicateTable:ERROR:relation&#34; schema_migrations&#34;已存在
我已经注释了存储schema_migration表创建定义的行,例如在development_structure.sql和test_structure.sql文件中。但它仍然给我带来了错误。
我不知道schema_migration表的创建位置。我的项目中没有schema_migration.rb文件。
请帮助我解决这个问题。提前谢谢!
这是我的错误日志。
rake aborted!
PG::DuplicateTable: ERROR: relation "schema_migrations" already exists
: CREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL)
/home/bit/.rvm/gems/ruby-2.1.5/gems/activerecord-2.3.18/lib/active_record/connection_adapters/abstract_adapter.rb:227:in `rescue in log'
/home/bit/.rvm/gems/ruby-2.1.5/gems/activerecord-2.3.18/lib/active_record/connection_adapters/abstract_adapter.rb:204:in `log'
/home/bit/Development/app2/application/lib/core_extensions/postgresql_adapter/reconnect.rb:26:in `execute'
/home/bit/.rvm/gems/ruby-2.1.5/gems/activerecord-2.3.18/lib/active_record/connection_adapters/abstract/schema_statements.rb:109:in `create_table'
/home/bit/.rvm/gems/ruby-2.1.5/gems/activerecord-2.3.18/lib/active_record/connection_adapters/abstract/schema_statements.rb:371:in `initialize_schema_migrations_table'
/home/bit/.rvm/gems/ruby-2.1.5/gems/activerecord-2.3.18/lib/active_record/migration.rb:441:in `initialize'
/home/bit/.rvm/gems/ruby-2.1.5/gems/rails-2.3.18/lib/tasks/databases.rake:193:in `new'
/home/bit/.rvm/gems/ruby-2.1.5/gems/rails-2.3.18/lib/tasks/databases.rake:193:in `block (2 levels) in <top (required)>'
/home/bit/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
/home/bit/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:seed => db:seed:common => db:seed:original => db:abort_if_pending_migrations
(See full trace by running task with --trace)
答案 0 :(得分:0)
如果可以在本地删除数据,请尝试
Logger
再次播种。我过去曾遇到过类似的问题,我在没有正确回滚的情况下删除了迁移,这就是解决方案。
如果您需要保留它,请打开rails数据库(终端rake db:drop db:create db:migrate
)并尝试
rails db
(此后再次使用drop table schema_migrations
运行迁移)
编辑:这还没有解决问题,但似乎可能还有其他问题需要考虑.OP无法启动rails console和接收
db:migrate
每次都是错误信息 - 如果有人有想法,请添加答案!