我正在尝试建立一个新的Rails 5应用程序(ruby 2.3.1,rails 5.0.0.rc1),使用postgresql、devise宝石,并且由于以下错误导致无法运行rails db:seed
:
PG::UndefinedTable: ERROR: relation "application_records" does not exist
LINE 8: WHERE a.attrelid = '"application_records"'::r...
^
/Users//.rvm/gems/ruby-2.3.1@rails5.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/postgresql/database_statements.rb:88:in `async_exec'
/Users/foo/.rvm/gems/ruby-2.3.1@rails5.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/postgresql/database_statements.rb:88:in `block in query'
/Users/foo/.rvm/gems/ruby-2.3.1@rails5.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:566:in `block in log'
/Users/foo/.rvm/gems/ruby-2.3.1@rails5.0/gems/activesupport-5.0.0.rc1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/foo/.rvm/gems/ruby-2.3.1@rails5.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:560:in `log'
/Users/foo/.rvm/gems/ruby-2.3.1@rails5.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/postgresql/database_statements.rb:87:in `query'
/Users/foo/.rvm/gems/ruby-2.3.1@rails5.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:739:in `column_definitions'
/Users/foo/.rvm/gems/ruby-2.3.1@rails5.0/gems/activerecord-5.0.0.rc1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:227:in `columns'
经过大量的搜索,我意识到这与 Rails 5中ApplicationRecord基类更改有关。显然没有叫做application_records
的表,所以active_support不应该寻找它。我已经检查了app/models/application_record.rb
是否存在并且内容正确。此外,用户模型(目前是我的应用程序中唯一的模型)按预期扩展了ApplicationRecord:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable
end
"
rails db: migrate
命令可以正常运行,但是 rails db:seed
命令出现了上述错误。
有人能够解释一下可能是什么原因导致这个问题吗?
application_record.rb
文件的内容如下:
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
application_record.rb
文件包含什么内容? - Prathamesh Sonpatki