简体   繁体   English

PG undefinedtable 错误关系用户不存在

[英]PG undefinedtable error relation users does not exist

I saw this question up before, but only for rspec. I haven't created test yet because it's too advanced for me but one day soon i will: :P我以前看到过这个问题,但只针对 rspec。我还没有创建测试,因为它对我来说太高级了,但很快我就会::P

I get this error when I try to sign-up/login into my app.当我尝试注册/登录我的应用程序时出现此错误。 I used devise to create user and also omniauth2 to sign-in with google .我使用 devise 创建用户,还使用omniauth2使用google登录。

this is the error这是错误

ActiveRecord::StatementInvalid at /users/auth/google_oauth2/callback
PG::UndefinedTable: ERROR:  relation "users" does not exist
LINE 5:              WHERE a.attrelid = '"users"'::regclass
                                        ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"users"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

I tried rake db:migrate , but it already is created: in schema table users exist.我试过rake db:migrate ,但它已经创建:在模式表中存在用户。 Has anyone got this error before?以前有人遇到过这个错误吗?

database.yml数据库.yml

config=/opt/local/lib/postgresql84/bin/pg_config配置=/opt/local/lib/postgresql84/bin/pg_config

development:
  adapter: postgresql
  encoding: unicode
  database: tt_intraweb_development
  pool: 5
  username: my_username
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: tt_intraweb_test
  pool: 5
  username: my_username
  password:

production:
  adapter: postgresql
  encoding: unicode
  database: tt_intraweb_production
  pool: 5
  username: my_username
  password:

At first, you shall detach all connections out of database.首先,您应该将所有连接从数据库中分离出来。 By default you use the development environment.默认情况下,您使用开发环境。 Then try to reset database with the following:然后尝试使用以下命令重置数据库:

rake db:reset

The rake db:reset task will drop the database and set it up again. rake db:reset 任务将删除数据库并重新设置它。 This is functionally equivalent to rake db:drop db:setup.这在功能上等同于 rake db:drop db:setup。

This is not the same as running all the migrations.这与运行所有迁移不同。 It will only use the contents of the current schema.rb file.它只会使用当前 schema.rb 文件的内容。 If a migration can't be rolled back, rake db:reset may not help you.如果迁移无法回滚, rake db:reset 可能无济于事。 To find out more about dumping the schema see Schema Dumping and You section.要了解有关转储架构的更多信息,请参阅架构转储和您部分。 Rails Docs Rails 文档

If the trick doesn't help, drop the database, then re-create it again, migrate data, and if you have seeds, sow the database:如果技巧没有帮助,删除数据库,然后重新创建它,迁移数据,如果你有种子,播种数据库:

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

or in short way (since 3.2):或简而言之(自 3.2 起):

rake db:migrate:reset db:seed

Since db:migrate:reset implies drop, create and migrate the db.由于db:migrate:reset意味着删除、创建和迁移数据库。 Because the default environment for rake is development , in case if you see the exception in spec tests, you should re-create db for the test environment as follows:因为rake的默认环境是development ,如果你在 spec 测试中看到异常,你应该为测试环境重新创建 db 如下:

RAILS_ENV=test rake db:drop db:create db:migrate

or with just loading the migrated scheme:或者只加载迁移的方案:

RAILS_ENV=test rake db:drop db:create db:schema:load

In most cases the test database is being sowed during the test procedures, so db:seed task action isn't required to be passed.在大多数情况下,测试数据库是在测试过程中播种的,因此不需要通过db:seed任务操作。 Otherwise, you shall to prepare the database (this is deprecated in Rails 4 ):否则,您应该准备数据库(这在Rails 4 中已弃用):

rake db:test:prepare

and then (if it is actually required):然后(如果确实需要):

RAILS_ENV=test rake db:seed

On newer versions of Rails the error ActiveRecord::NoEnvironmentInSchemaError may be risen, so just prepend the tasks with a database environment set task: db:environment:set :在较新版本的 Rails 上,错误ActiveRecord::NoEnvironmentInSchemaError可能会出现,因此只需在任务前面加上数据库环境集任务: db:environment:set

RAILS_ENV=test rake db:environment:set db:drop db:create db:migrate

I encountered this error, and upon my research, found out that one of the reasons for PG undefinedtable error relation users does not exist error is:我遇到了这个错误,经过我的研究,发现PG undefinedtable错误关系用户不存在错误的原因之一是:

This error is a migration error.此错误是迁移错误。 You may have created new model with some database attributes.您可能创建了具有某些数据库属性的新模型。 After creating model you have to migrate attributes to your rails app schema.创建模型后,您必须将属性迁移到 Rails 应用程序架构。

If you are using local machine, for development, you can use command如果您使用的是本地机器,对于开发,您可以使用命令

rake db:migrate

If you're using heroku如果您使用的是heroku

heroku run rake db:migrate

Your test database is not ready for rspec.您的测试数据库还没有为 rspec 做好准备。

Prepare your test database for rspec to fix this error为 rspec 准备测试数据库以修复此错误

RAILS_ENV=test rake test:prepare

It will drop, create and add migrations to your test database它将删除、创建和添加迁移到您的测试数据库

In case rake task is aborted with message like 'PG::Error: ERROR: database "[your_db_test]" is being accessed by other users' execute this one如果 rake 任务被中止,并出现“PG::Error: ERROR: database "[your_db_test]" is being accessing by other users' 之类的消息,请执行此操作

RAILS_ENV=test rake db:migrate

I had a similar error.我有一个类似的错误。 The root of my error was that I had a reference to a Rails model in my factories.rb file.我的错误根源在于我在 factory.rb 文件中引用了 Rails 模型。 So it caused a load error issue.所以它导致了加载错误问题。 The fix was to wrap the reference in a block or {} so that it delays running it.修复方法是将引用包装在块或{}以便延迟运行它。

Here was the BROKEN code:这是破碎的代码:

FactoryGirl.define do
  factory :user do
    guid User.new.send(:new_token)
  end
end

And it was erroring because User was not defined when factories.rb was being loaded.它是错误的,因为在加载 factory.rb 时没有定义User I wrapped the User.new call in a block and it solved the issue:我将User.new调用包装在一个块中,它解决了这个问题:

Fixed code:固定代码:

FactoryGirl.define do
  factory :user do
    guid { User.new.send(:new_token) }
  end
end

Note: probably not best practice to need to call your model like this, but it was a solution to DRY up my code.注意:可能不是需要像这样调用模型的最佳实践,但它是干掉我的代码的解决方案。

I was getting this error as well when running rspec:运行 rspec 时,我也收到此错误:

 Failure/Error: it { expect(subject.priority_list).to eq [nil] * 9 }
 ActiveRecord::StatementInvalid:
   PG::UndefinedTable: ERROR:  relation "priorities" does not exist
   LINE 5:              WHERE a.attrelid = '"priorities"'::regclass
 ...

It was resolved for me after I ran跑完后为我解决了

rake db:test:prepare
rake db:test:load

This is often caused by a bug in ActiveAdmin.这通常是由 ActiveAdmin 中的错误引起的。 Here's how to get around the bug:以下是解决该错误的方法:

If you're using ActiveAdmin, whichever table PG says doesn't exist, comment out the contents of that ActiveAdmin rb file.如果您正在使用 ActiveAdmin,无论 PG 说哪个表不存在,请注释掉该 ActiveAdmin rb 文件的内容。

For example, for this case PGError: ERROR: relation "users" does not exist , comment out the entire contents of app/admin/users.rb , then uncomment after you've done your migrations.例如,对于这种情况PGError: ERROR: relation "users" does not exist ,注释掉app/admin/users.rb的全部内容,然后在完成迁移后取消注释。

That issue for me was being caused by Factory Girl rails.对我来说,这个问题是由 Factory Girl 导轨引起的。 I would recommend for those using it to rename the specs/factories folder to specs/temp and attempting我会建议那些使用它重命名 specs/factories 文件夹的人为 specs/temp 并尝试

RAILS_ENV=your_environment bundle exec rake db:migrate --trace RAILS_ENV=your_environment bundle exec rake db:migrate --trace

If it passes, then you just found what was causing it.如果它通过了,那么您就找到了导致它的原因。 A quick dig through the Factory Girl Rails gem github repo helped me identify the issue.快速浏览 Factory Girl Rails gem github repo 帮助我确定了问题。

The factories were failing because I was trying to instantiate a Model that didn't exist upon running!工厂失败了,因为我试图实例化一个运行时不存在的模型! Code sample below:下面的代码示例:

FactoryGirl.define do
  factory :billing_product, class: 'Billing::Product' do
    name            Faker::Cat.name
    product_type    'fuel'
    active          true
    payment_options [Billing::PaymentOption.new(term: 1, payment_term: 1)]
  end
end

Encapsulating the Array in a block (adding {}) did the fix for me.将数组封装在一个块中(添加 {})为我做了修复。 Note that payment_options can take more than one payment option in the example...请注意,在示例中,payment_options 可以采用多个付款选项...

payment_options {[Billing::PaymentOption.new(term: 1, payment_term: 1)]}

Refer to the Dynamic Attributes part of the Factory Girl Rails docs for more info.有关更多信息,请参阅Factory Girl Rails 文档动态属性部分

Don't forget to rename your factories folder back!不要忘记重命名您的工厂文件夹!

I was facing the same problem and then I discovered the following solution.我遇到了同样的问题,然后我发现了以下解决方案。

Make sure You have entered all of the following credentials in the database.yml file and they are correct:确保您在 database.yml 文件中输入了以下所有凭据并且它们是正确的:

development:
 adapter: postgresql
 encoding: unicode
 database: my_database
 host: localhost
 port: 5432
 pool: 5
 username: postgres
 password: xyz

test:
 adapter: postgresql
 encoding: unicode
 database: my_test_database
 host: localhost
 port: 5432
 pool: 5
 username: postgres
 password: xyz 

I had this problem after I deleted the users table.删除用户表后我遇到了这个问题。 solutions was changing解决方案正在改变

change_table(:users)

to

create_table(:users)

::Migration[5.0] was missing in migrations. ::Migration[5.0]在迁移中丢失。 instead of throwing syntax error it throws它抛出的不是抛出语法错误

PG::UndefinedTable: ERROR: relation roles does not exists PG::UndefinedTable:错误:关系角色不存在

after wasting hours I finally figured out that migration is missing ::Migration[5.0] .在浪费了几个小时之后,我终于发现缺少::Migration[5.0]

Erroneous Migration:错误迁移:

class CreateRoles < ActiveRecord # <---- Pay attention
  def change
    create_table :roles do |t|
      t.string :name
      t.integer :code, limit: 2
      t.boolean :is_active, default: true

      t.timestamps
    end
  end
end

Fixed and Correct Migration固定和正确的迁移

class CreateRoles < ActiveRecord::Migration[5.0]
  def change
    create_table :roles do |t|
      t.string :name
      t.integer :code, limit: 2
      t.boolean :is_active, default: true

      t.timestamps
    end
  end
end

This could be a bug with rails and might help someone, instead of struggling and wondering.这可能是 rails 的一个错误,可能会帮助某人,而不是挣扎和疑惑。

I was getting a similar error while trying to run tests using rspec.我在尝试使用 rspec 运行测试时遇到了类似的错误。

I followed Малъ Скрылевъ's steps but still ended up short.我跟着 Малъ Скрылевъ 的步骤走,但还是没能成功。 The final step I needed to do was load my schema into my test database using:我需要做的最后一步是使用以下命令将模式加载到我的测试数据库中:

RAILS_ENV=test rake db:schema:load

After that the problem went away and I could move on to the next bug.之后问题就消失了,我可以继续下一个错误。 Hopefully that gives you some insight.希望这能给你一些见解。

删除 Admin 文件夹并再次运行 rake。

(I know this is old, but for future googlers) (我知道这是旧的,但对于未来的谷歌员工)

Are you using devise ?你在使用devise吗? I know specifically omniauthable is a problem, but maybe others as well.我知道特别是omniauthable是一个问题,但也许其他人也是如此。 It doesn't have to be devise though.不过也不一定非要devise Generically the solution is to comment out the offending model, class, whatever, and un-comment any sections the errors ask for.通常,解决方案是注释掉有问题的模型、类等,并取消注释错误要求的任何部分。

For me, what was happening is that devise is reading the User model to see what you have as arguments for devise (the class method ie devise :database_authenticatable, :registerable #etc )对我来说,正在发生的事情是devise正在读取User模型以查看您作为devise参数的内容(类方法即devise :database_authenticatable, :registerable #etc

But, it will read the whole file and if this isn't a new project it might get tripped up by other class methods relying on other things (in my case it was the friendly_id gem, and then an alias_method但是,它会读取整个文件,如果这不是一个新项目,它可能会被依赖其他东西的其他类方法绊倒(在我的情况下,它是friendly_id gem,然后是alias_method

The answer was to comment out the User model except for the devise lines(s) * and rake db:schema:load should run fine.答案是注释掉User模型,除了devise行 * 和rake db:schema:load应该可以正常运行。

  • otherwise I got this error:否则我会收到这个错误:

    ArgumentError: Mapping omniauth_callbacks on a resource that is not omniauthable Please add devise :omniauthable to the User model ArgumentError: 在非 omniauthable 的资源上映射 omniauth_callbacks 请添加devise :omniauthableUser模型

If you get this error while migrating, make sure your model name is plural如果您在迁移时遇到此错误,请确保您的模型名称是复数

e,g.例如

add_column :images, :url, :string

最可能的原因是您的 rake 使用的环境与 database.yml 不同,而不是您的网络服务器。

I had this problem and it turned out to be caused by Grape API .我遇到了这个问题,结果证明是由Grape API引起的。 I noticed in the stack trace that the routes file was being read during the migration.我在堆栈跟踪中注意到在迁移过程中正在读取路由文件。

In routes.rb the Grape api is mounted在 routes.rb 中安装了 Grape api

mount API::Base => '/'

And in the API were references to the missing model.在 API 中是对缺失模型的引用。 So, thanks to this answer I put it in a block that detects whether its being run by the server or during the migration.因此,由于这个答案,我将它放在一个块中,以检测它是由服务器运行还是在迁移过程中运行。

unless ( File.basename($0) == "rake" && ARGV.include?("db:migrate") )
    mount API::Base => '/'
end

And it worked.它奏效了。

I was having the following error and doing a lookup into all my application code for type_zones I was unable to find it.我遇到了以下错误,并在查找type_zones所有应用程序代码时找不到它。 I also looked at the db and it was updated.我还查看了 db,它已更新。

Turns out it was a file under fixtures /test/fixtures/type_zones.yml that was causing the trouble.原来是fixtures /test/fixtures/type_zones.yml下的一个文件导致了问题。

ERROR["test_should_get_new", UsersControllerTest, 0.47265757399145514]
test_should_get_new#UsersControllerTest (0.47s)
ActiveRecord::StatementInvalid:  ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "type_zones" does not exist
    LINE 1: DELETE FROM "type_zones"
                        ^
    : DELETE FROM "type_zones"

For anyone who is still having this problem, in my case, it was my factory in FactoryGirl that was triggering this error.对于仍然遇到此问题的任何人,就我而言,是我在 FactoryGirl 的工厂触发了此错误。

I was trying to add reference via '.new' or '.create'.我试图通过“.new”或“.create”添加引用。

In my case, I had to comment out 2 ActiveAdmin files.就我而言,我不得不注释掉2 个ActiveAdmin文件。 Here were my steps:这是我的步骤:

  1. Initial error/stacktrace (note we're using Solr on this project): ⇒ rkdbm java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode) => Solr is already running rake aborted! PG::UndefinedTable: ERROR: relation "discussions" does not exist LINE 5: WHERE a.attrelid = '"discussions"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"discussions"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/app/admin/users.rb:25:in block in <top (required)>' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/app/admin/users.rb:1:in ' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/config/routes.rb:3:in block in <top (required)>' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/config/routes.rb:1:in ' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/config/environment.rb:5:in `' Tasks: TOP => db:migrate => environment (See full trace by running task with --trace)初始错误/ ⇒ rkdbm java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode) => Solr is already running rake aborted! PG::UndefinedTable: ERROR: relation "discussions" does not exist LINE 5: WHERE a.attrelid = '"discussions"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"discussions"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/app/admin/users.rb:25:in block in <top (required)>' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/app/admin/users.rb:1:in ' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/config/routes.rb:3:in block in <top (required)>' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/config/routes.rb:1:in ' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/config/environment.rb:5:in `' Tasks: TOP => db:migrate => environment (See full trace by running task with --trace) (注意我们在这个项目中使用Solr ): ⇒ rkdbm java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode) => Solr is already running rake aborted! PG::UndefinedTable: ERROR: relation "discussions" does not exist LINE 5: WHERE a.attrelid = '"discussions"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"discussions"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/app/admin/users.rb:25:in block in <top (required)>' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/app/admin/users.rb:1:in ' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/config/routes.rb:3:in block in <top (required)>' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/config/routes.rb:1:in ' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/config/environment.rb:5:in `' Tasks: TOP => db:migrate => environment (See full trace by running task with --trace) ⇒ rkdbm java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode) => Solr is already running rake aborted! PG::UndefinedTable: ERROR: relation "discussions" does not exist LINE 5: WHERE a.attrelid = '"discussions"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"discussions"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/app/admin/users.rb:25:in block in <top (required)>' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/app/admin/users.rb:1:in ' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/config/routes.rb:3:in block in <top (required)>' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/config/routes.rb:1:in ' /Users/matthewcampbell/Sites/code/stack-builders/AchieveX/config/environment.rb:5:in `' Tasks: TOP => db:migrate => environment (See full trace by running task with --trace)

I commented out the app/admin/discussions.rb file per Arcolye's answer above and tried to migrate my database again.我根据上面 Arcolye 的回答注释掉了app/admin/discussions.rb文件并尝试再次迁移我的数据库。

Same error.同样的错误。

I looked at the stacktrace a bit more closely, and noticed that in fact app/admin/users.rb:25 was throwing the exception - and sure enough, that file has a dependency on my discussions table (via executing Discussion.all ).我更仔细地app/admin/users.rb:25 ,并注意到实际上app/admin/users.rb:25正在抛出异常 - 果然,该文件依赖于我的discussions表(通过执行Discussion.all )。

Finally, commenting out the contents of users.rb allowed me to finally migrate my database successfully.最后,注释掉users.rb的内容让我最终成功迁移了我的数据库。

FYI: there's a discussion here in ActiveAdmin about whether that gem should load the database when required.仅供参考: ActiveAdmin讨论该 gem 是否应在需要时加载数据库。

So having the same problem just now.所以刚刚遇到同样的问题。 Remember to have only one model in each migration.记住在每次迁移中只有一个模型。 That solved it for me.那为我解决了。

I came across the answer here.我在这里找到了答案。

I was catching the Error:我发现了错误:

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "users" does not exist
LINE 8:                WHERE a.attrelid = '"users"'::regclass

It turned out to be a super easy fix.结果证明这是一个超级简单的修复。 I had copied files over from an older version of the project and forgot to nest them inside of a "migrate" folder.我从旧版本的项目复制了文件,忘记将它们嵌套在“迁移”文件夹中。 When I did that it solved the problem for me.当我这样做时,它为我解决了问题。

it usually can happen when you use wrong type of association between models, check for dependency destroy and has_many associations, for example:当您在模型之间使用错误类型的关联,检查依赖关系破坏和 has_many 关联时,通常会发生这种情况,例如:

wrong way that can cause this trouble:可能导致此问题的错误方式:

article.rb文章.rb

 has_many :subcategories, through: :categories, dependent: :destroy

subcategory.rb子类别.rb

has_and_belongs_to_many :articles

right way:正确方法:

article.rb文章.rb

 has_many :subcategories, through: :categories, dependent: :destroy

subcategory.rb子类别.rb

declare association with categories here not articles (belongs_to / has_many_and_belongs_to)

Forgetting the migration file in your commit can cause this issue.忘记提交中的迁移文件可能会导致此问题。 When pushed on heroku for eg rails db:migrate will obviously not work.当在 heroku 上推送时,例如rails db:migrate显然不起作用。 Be sure that the migration file defining the undefined table have been committed.确保定义未定义表的迁移文件已经提交。

My case was also related to FactoryGirl / FactoryBot and I just had to change the definition.我的情况也与FactoryGirl / FactoryBot ,我只需要更改定义即可。 Replacing the constant by a string.用字符串替换常量。

My env:我的环境:

Rails 5.2.6
factory_bot 4.8.2

From this:由此:

FactoryBot.define do
  factory :user, class: Admin::User do
    ...
  end
end

To this:对此:

FactoryBot.define do
  factory :user, class: 'Admin::User' do
    ...
  end
end

Which is something recommended by Getting Started - Specifying the class explicitly .这是入门指南推荐的内容- 明确指定类

I was trying to run test.rake script and encountered the same issue.我试图运行 test.rake 脚本并遇到了同样的问题。 Spent a lot of time trying to understand what's going on.花了很多时间试图了解发生了什么。 Eventually, it get fixed after I renamed the file.最终,在我重命名文件后它得到修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 迁移错误PG :: UndefinedTable:错误:关系“用户”不存在 - Migration error PG::UndefinedTable: ERROR: relation “users” does not exist PG :: UndefinedTable:错误:关系“用户”不存在-Azure数据库 - PG::UndefinedTable: ERROR: relation “users” does not exist - Azure database 持续集成问题 - PG :: UndefinedTable:错误:关系“用户”不存在 - Continuous Integration issue — PG::UndefinedTable: ERROR: relation “users” does not exist Rails 6:PG :: UndefinedTable:错误:关系“用户”不存在 - Rails 6: PG::UndefinedTable: ERROR: relation “users” does not exist PG :: UndefinedTable:错误:关系“事件”不存在 - PG::UndefinedTable: ERROR: relation “events” does not exist PG :: UndefinedTable:错误:关系“ carrinho”不存在 - PG::UndefinedTable: ERROR: relation “carrinho” does not exist Rails:PG::UndefinedTable:错误:关系“...”不存在 - Rails: PG::UndefinedTable: ERROR: relation "..." does not exist PG::UndefinedTable:错误:关系“条目”不存在 - PG::UndefinedTable: ERROR: relation "entries" does not exist PG :: UndefinedTable:错误:关系&#39;洞穴&#39;不存在 - PG::UndefinedTable: ERROR: relation 'caves' does not exist PG :: UndefinedTable:错误:关系不存在 - PG::UndefinedTable: ERROR: relation does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM