gpt4 book ai didi

mysql - 没有这样的列 : admin_users. 密码

转载 作者:太空宇宙 更新时间:2023-11-03 12:17:18 24 4
gpt4 key购买 nike

当我在 Rails 中运行迁移时,我收到一个 SQL 错误,指出不存在这样的列:admin_users.password。当我 SHOW FIELDS 时,它显然就在那里。我确定这是因为我在某处遗漏了一些东西。在这种情况下,了解出了什么问题对我来说比解决问题重要得多,因为我的数据库一直处于损坏状态。

First Migration:

class CreateUsers < ActiveRecord::Migration

def up
create_table :users do |t|
t.column "first_name", :string, :limit => 25
t.string "last_name", :limit => 50
t.string "email", :default => "", :null => false
t.string "password:", :limit => 40
# t.datetime "created_at"
# t.datetime "updated_at"
# The above two are created automatically by the below command
t.timestamps
end
end

def down
drop_table :users
end

end

Second Migration:

class AlterUsers < ActiveRecord::Migration


def up
rename_table("users", "admin_users")
add_column("admin_users", "username", :string, :limit => 25, :after => "email")
change_column("admin_users", "email", :string, :limit => 100)
rename_column("admin_users", "password", "hashed_password")
puts "*** Adding an index is next***"
add_index("admin_users", "username")
end

def down
remove_index("admin_users", "username")
rename_column("admin_users", "hashed_password", "password")
change_column("admin_users", "email", :default => "", :null => false)
remove_column("admin_users", "username")
rename_table("admin_users", "users")
end
end


=>== CreateUsers: migrated (0.0163s) ===========================================

== AlterUsers: migrating =====================================================
-- rename_table("users", "admin_users")
-> 0.0034s
-- add_column("admin_users", "username", :string, {:limit=>25, :after=>"email"})
-> 0.0158s
-- change_column("admin_users", "email", :string, {:limit=>100})
-> 0.2273s
-- rename_column("admin_users", "password", "hashed_password")
rake aborted!
An error has occurred, all later migrations canceled:

No such column: admin_users.password

最佳答案

那是因为您在第一次迁移中用冒号调用了您的列password:

我敢打赌这是因为 rails generate model 命令行中的拼写错误。这绝对不是万无一失的。

关于mysql - 没有这样的列 : admin_users. 密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21551130/

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