I'm running this migration:
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
I get an error saying:
rails db:migrate rails aborted! Mysql2::Error: Access denied for user 'root'@'localhost' (using password: YES)
For the first, this is correct migration code:
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
or just change 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
About error, your database.yml
for development env, should looks like this:
development:
adapter: mysql2
encoding: utf8
database: your_db_name
username: your_user
password: your_password
host: 127.0.0.1
port: 3306
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments