gpt4 book ai didi

ruby-on-rails - Rails 迁移——rake db :status says migration is down, 但数据库已经迁移?

转载 作者:行者123 更新时间:2023-11-29 12:05:55 25 4
gpt4 key购买 nike

我有一个本地 PSQL 数据库设置,但在让 rake db:migrate 正常运行时遇到了问题。例如,我的数据库已经将其 high_school 列名称更改为 high_school_name,但是 rake db:migrate 失败了,状态显示如下:

up     20130307043554  Adding seo tables
up 20130307185401 Create admin notes
up 20130307185402 Move admin notes to comments
up 20130308160956 Add active flad to users
up 20130308214928 Add column public to users table
up 20130325203837 Add duration to videos
up 20130326171803 Update duration of videos
down 20130410145000 Fix high school name
up 20130410145028 Add high school id to users
up 20130410161705 Convert units for stats
up 20130410164209 ********** NO FILE **********
up 20130416142844 Add column coach id to users

为什么迁移顺序中间的迁移失败/被解读为“宕机”?这是错误:

Migrating to AddingSeoTables (20130307043554)
Migrating to CreateAdminNotes (20130307185401)
Migrating to MoveAdminNotesToComments (20130307185402)
Migrating to AddActiveFladToUsers (20130308160956)
Migrating to AddColumnPublicToUsersTable (20130308214928)
Migrating to AddDurationToVideos (20130325203837)
Migrating to UpdateDurationOfVideos (20130326171803)
Migrating to FixHighSchoolName (20130410145000)
(0.1ms) BEGIN
== FixHighSchoolName: migrating ==============================================
-- rename_column(:users, :high_school, :high_school_name)
(0.4ms) ALTER TABLE "users" RENAME COLUMN "high_school" TO "high_school_name"
PG::Error: ERROR: column "high_school" does not exist
: ALTER TABLE "users" RENAME COLUMN "high_school" TO "high_school_name"
(0.1ms) ROLLBACK
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::Error: ERROR: column "high_school" does not exist
: ALTER TABLE "users" RENAME COLUMN "high_school" TO "high_school_name"

显然,存在架构问题或其他问题。虽然通过远程分支跟踪模式,所以我不知道问题出在哪里。

最佳答案

我怀疑 down 无法正确处理列重命名更改,除非只是添加或删除列。

您可能希望考虑的一个选项实际上是使用 SQL 更改名称。例如,如果将 high_school 更改为 high_school_name 的迁移失败并且数据库本身当前有 high_school_name,请将其重命名(在 SQL 中)为 high_school 然后尝试运行迁移。这可能是您的一个选择。

关于ruby-on-rails - Rails 迁移——rake db :status says migration is down, 但数据库已经迁移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16046126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com