PG undefinedtable错误关系用户不存在

编程入门 行业动态 更新时间:2024-10-24 16:25:57
本文介绍了PG undefinedtable错误关系用户不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我之前看到这个问题,但只有rspec。我不是创建测试,因为它太早了我,但有一天很快我会! :P

我尝试注册/使用我的应用程序登录时收到此错误。我不知道在哪里寻找解决它。我使用devise创建我的用户以及 omniauth2 以使用 google 登录。

这是错误

ActiveRecord :: StatementInvalid at / users / auth / google_oauth2 / callback PG :: UndefinedTable:ERROR:relationusers不存在 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

我试过 rake db:migrate ,但它已经创建,在模式表用户存在。有谁得到这个错误之前?

database.yml

gem install pg - --with-pg-config = / opt / local / lib / postgresql84 / bin / pg_config #在Windows上:#gem install pg #选择win32 build 。 #安装PostgreSQL并把它的/ bin目录放在你的路径上。 ##配置使用Gemfile #gem'pg'#开发:适配器:postgresql 编码:unicode 数据库:tt_intraweb_development 池:5 用户名:my_username 密码: #在TCP套接字上连接。默认情况下省略,因为客户端使用不需要配置的#域套接字。 Windows没有#域套接字,因此取消注释这些行。 #host:localhost #port:5432 #模式搜索路径。服务器默认为$ user,public #schema_search_path:myapp,sharedapp,public #按升序排列的最小日志级别:#debug5,debug4,debug3,debug2, debug1,#log,notice,warning,error,fatal和panic #服务器默认为通知。 #min_messages:warning #警告:当您运行rake时,定义为test的数据库将被清除,#从开发数据库中重新生成。 #不要将此数据库设置为与开发或生产相同。 test: adapter:postgresql encoding:unicode database:tt_intraweb_test pool:5 用户名:my_username 密码: b 生产:适配器:postgresql 编码:unicode 数据库:tt_intraweb_production 池:5 用户名:my_username 密码:

谢谢!

解决方案

首先,你应该将所有连接从数据库中分离出来。默认情况下,您可以使用开发环境。然后尝试使用以下命令重置数据库:

rake db:reset pre>

rake db:reset任务将删除数据库并重新设置。这在功能上等同于rake db:drop db:setup。

这与运行所有迁移不同。它将只使用当前schema.rb文件的内容。如果无法回滚迁移,则 rake db:reset可能无法帮助您。要了解更多关于转储模式的信息,请参阅 Schema Dumping and You节。 Rails文档

如果窍门没有帮助,删除数据库,然后重新创建它,迁移数据,如果你有种子,播种数据库:

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

或简称(从3.2开始):

rake db:migrate:reset db :seed

$ b $ p db:migrate:reset 隐含drop,创建和迁移db。因为 rake 的默认环境是开发,如果在规范测试中看到异常,您应该重新创建 > test 环境如下:

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

或只需加载迁移的方案:

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

在大多数情况下,测试数据库正在测试过程中播放,因此不需要传递 db:seed 任务操作。否则,您将准备数据库(这在 Rails 4 中已弃用):

rake db :test:prepare

然后(如果实际需要的话):

RAILS_ENV = test rake db:seed

I see this question up before, but only for rspec. I am not create test yet because its too advance for me but one day soon i will! :P

I am getting this error when i try to sign up/ log in with my app. I'm not sure where to look to fix it. I use devise to create my user and also omniauth2 to sign in with 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. has anyone get this error before?

database.yml

# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config # On Windows: # gem install pg # Choose the win32 build. # Install PostgreSQL and put its /bin directory on your path. # # Configure Using Gemfile # gem 'pg' # development: adapter: postgresql encoding: unicode database: tt_intraweb_development pool: 5 username: my_username password: # Connect on a TCP socket. Omitted by default since the client uses a # domain socket that doesn't need configuration. Windows does not have # domain sockets, so uncomment these lines. #host: localhost #port: 5432 # Schema search path. The server defaults to $user,public #schema_search_path: myapp,sharedapp,public # Minimum log levels, in increasing order: # debug5, debug4, debug3, debug2, debug1, # log, notice, warning, error, fatal, and panic # The server defaults to notice. #min_messages: warning # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. 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:

Thank you!

解决方案

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. This is functionally equivalent to 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. If a migration can't be rolled back, rake db:reset may not help you. To find out more about dumping the schema see Schema Dumping and You section. Rails Docs

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):

rake db:migrate:reset db:seed

Since db:migrate:reset implies drop, create and migrate the db. 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:

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. Otherwise, you shall to prepare the database (this is deprecated in Rails 4):

rake db:test:prepare

and then (if it is actually required):

RAILS_ENV=test rake db:seed

更多推荐

PG undefinedtable错误关系用户不存在

本文发布于:2023-10-14 11:56:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1490991.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在   错误   关系   用户   PG

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!