推送到 Heroku - 活动记录::语句无效:PG::未定义表:错误:关系"users"不存在



我现在真的很沮丧。

我在本地有我的workingrails应用程序,并希望将其部署到Heroku。到目前为止还不错。

每当我试图将代码推送到Heroku时,它都会抛出一个错误,即找不到表。我确实试过几次运行heroku run rails db:migrate db:drop db:reset或其他什么程序,但都没有成功。

development:
<<: *default
database: postgres
encoding: utf8

# 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:
<<: *default
adapter: postgresql
database: fortest
production:
<<: *default
adapter: postgresql
url: <%= ENV['DATABASE_URL'] %>

我所有的表和迁移在我的本地机器上都运行良好,问题是我需要在Heroku上运行这些迁移来创建我的数据库表,但不知何故不能,因为当我的预编译资产启动时它会失败。

Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        rake aborted!
remote:        ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "users" does not exist
remote:        LINE 8:                WHERE a.attrelid = '"users"'::regclass
remote:                                                  ^
remote:        :               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
remote:                             pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
remote:                             c.collname, col_description(a.attrelid, a.attnum) AS comment
remote:                        FROM pg_attribute a
remote:                        LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
remote:                        LEFT JOIN pg_type t ON a.atttypid = t.oid
remote:                        LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
remote:                       WHERE a.attrelid = '"users"'::regclass
remote:                         AND a.attnum > 0 AND NOT a.attisdropped
remote:                       ORDER BY a.attnum

编辑:

在我的heroku日志中,它说构建失败——检查你的构建日志,在我的构建日志中,一切都正常,直到它到达以下路径:

Bundle completed (32.92s)
Cleaning up the bundler cache.
-----> Installing node-v8.10.0-linux-x64
-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "users" does not exist
LINE 8:                WHERE a.attrelid = '"users"'::regclass

更新:

Rake::Task["assets:precompile"].clear
namespace :assets do
task 'precompile' do
puts "Not pre-compiling assets..."
end
end

有了这个片段,我至少可以将我的文件推送到heroku。然而,我对所有db:migrate db:reset函数仍然有问题。db:migrate似乎有同样的错误。

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

db:create不知怎么给我抛出了这个错误

FATAL:  permission denied for database "postgres"
DETAIL:  User does not have CONNECT privilege.

我看到了所有的数据(用户名、密码、适配器、数据库、端口、主机(,它们都很好。

怎么样

$ git push heroku$ heroku run rake db:migrate

然后用另一个CCD_ 3再次启动资产预编译。

这里发生的情况是,您的routes.rb文件中很可能有一个devise_for :users,这导致Rails在启动时查找Users表,但由于您尚未运行迁移,因此找不到该表。

注释掉routes.rb中的devise_for并推送至Heroku-迁移将运行,然后取消注释devise_for并再次推送。

通常情况下,最好先创建Users表,然后在稍后的另一个步骤中将设计添加到模型中。

最新更新