我正在将Rails应用程序从GitHub推送到Heroku。 push命令成功执行,没有问题。但是,当我运行数据库迁移时,一次迁移成功运行,然后创建了另外两个表。创建这些表并且没有进一步的迁移时,该过程将退出。
我可以确认创建了users表。重新运行迁移会得到相同的结果
$ heroku run rake db:migrate
Running rake db:migrate on glacial-dawn-9135... starting, run.9094 (Free)
Running rake db:migrate on glacial-dawn-9135... connecting, run.9094 (Free)
Running rake db:migrate on glacial-dawn-9135... up, run.9094 (Free)
D, [2019-06-05T21:05:22.103433 #4] DEBUG -- : (6385.0ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL PRIMARY KEY)
D, [2019-06-05T21:05:22.211403 #4] DEBUG -- : (103.6ms) CREATE TABLE "ar_internal_metadata" ("key" character varying NOT NULL PRIMARY KEY, "value" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
D, [2019-06-05T21:05:22.215555 #4] DEBUG -- : (2.0ms) SELECT pg_try_advisory_lock(4036276764900377970)
D, [2019-06-05T21:05:22.526092 #4] DEBUG -- : (1.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
I, [2019-06-05T21:05:22.527894 #4] INFO -- : Migrating to DeviseCreateUsers (20190604184418)
D, [2019-06-05T21:05:22.532709 #4] DEBUG -- : (1.5ms) BEGIN
== 20190604184418 DeviseCreateUsers: migrating ================================
-- create_table(:users)
D, [2019-06-05T21:05:24.988378 #4] DEBUG -- : (2450.7ms) CREATE TABLE "users" ("id" bigserial primary key, "email" character varying DEFAULT '' NOT NULL, "encrypted_password" character varying DEFAULT '' NOT NULL, "reset_password_token" character varying, "reset_password_sent_at" timestamp, "remember_created_at" timestamp, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
-> 2.4556s
-- add_index(:users, :email, {:unique=>true})
D, [2019-06-05T21:05:25.086000 #4] DEBUG -- : (42.8ms) CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email")
-> 0.0974s
-- add_index(:users, :reset_password_token, {:unique=>true})
D, [2019-06-05T21:05:25.120170 #4] DEBUG -- : (29.5ms) CREATE UNIQUE INDEX "index_users_on_reset_password_token" ON "users" ("reset_password_token")
-> 0.0343s
== 20190604184418 DeviseCreateUsers: migrated (2.5877s) =======================
D, [2019-06-05T21:05:25.127740 #4] DEBUG -- : ActiveRecord::SchemaMigration Create (1.9ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20190604184418"]]
D, [2019-06-05T21:05:25.131447 #4] DEBUG -- : (3.4ms) COMMIT
D, [2019-06-05T21:05:25.142898 #4] DEBUG -- : ActiveRecord::InternalMetadata Load (1.7ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
D, [2019-06-05T21:05:25.153905 #4] DEBUG -- : (1.6ms) BEGIN
D, [2019-06-05T21:05:25.157339 #4] DEBUG -- : ActiveRecord::InternalMetadata Create (1.8ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "production"], ["created_at", "2019-06-05 21:05:25.154649"], ["updated_at", "2019-06-05 21:05:25.154649"]]
D, [2019-06-05T21:05:25.161052 #4] DEBUG -- : (2.9ms) COMMIT
D, [2019-06-05T21:05:25.163289 #4] DEBUG -- : (1.9ms) SELECT pg_advisory_unlock(4036276764900377970)
user@Desktop MINGW64 /c/PathMed (development)
我有12个迁移文件。在我的本地计算机(Windows)上进行迁移时没有问题。
编辑:这是rake db:migrate:status的输出
$ heroku run rake db:migrate:status
database: da599721qov2v0
Status Migration ID Migration Name
--------------------------------------------------
D, [2019-06-06T06:46:29.454045 #4] DEBUG -- : (1.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
up 20190604184418 Devise create users
此外,运行rake db:schema:load而不是db:migrate会导致相同的结果,即迁移了一张表。
更新2:我使用了schema.rb和迁移,并使用它们创建了一个空白的Rails应用程序。我能够顺利推送到heroku并运行迁移。我怀疑这是某个地方或与我的seed.rb文件有关的配置问题。任何人都对为什么有任何想法,还是我需要从头开始重新制作整个项目?
更新3:放弃,从头开始创建一个新项目,使用迁移从头开始生成模型,然后在所有应用程序逻辑之间进行复制。现在一切正常。