30 t.string "email", :d-6ren">
gpt4 book ai didi

mysql - rails db:migrate rails 中止! Mysql2::错误:用户 'root' @'localhost' 的访问被拒绝(使用密码:是)

转载 作者:行者123 更新时间:2023-11-30 21:47:23 25 4
gpt4 key购买 nike

我正在运行此迁移:

class CreateAdmins < ActiveRecord::Migration[5.1]
def change
create_table :admins do |t|

t.string "first_name" :limit => 30
t.string "last name", :limit => 30
t.string "email", :default => '', :null => false
t.string "password" ,:limit => 40
t.timestamps

end
end

def down
drop_table :admins
end
end

我收到一条错误消息:

rails db:migrate rails aborted! Mysql2::Error: Access denied for user 'root'@'localhost' (using password: YES)

最佳答案

首先,这是正确的迁移代码:

class CreateAdmins < ActiveRecord::Migration[5.1]
def self.up
create_table :admins do |t|
t.string :first_name, limit: 30
t.string :last_name, limit: 30
t.string :email, default: '', null: false
t.string :password ,limit: 40

t.timestamps
end
end

def self.down
drop_table :admins
end
end

或者只是改变 difference

class CreateAdmins < ActiveRecord::Migration[5.1]
def change
create_table :admins do |t|
t.string :first_name, limit: 30
t.string :last_name, limit: 30
t.string :email, default: '', null: false
t.string :password ,limit: 40

t.timestamps
end
end
end

关于错误,你的开发环境的database.yml应该是这样的:

development:
adapter: mysql2
encoding: utf8
database: your_db_name
username: your_user
password: your_password
host: 127.0.0.1
port: 3306

关于mysql - rails db:migrate rails 中止! Mysql2::错误:用户 'root' @'localhost' 的访问被拒绝(使用密码:是),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48830380/

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