这是我做的: 1. rails生成迁移DoNothingYet 调用active_record 20160919195736_do_nothing_yet.rb
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.dateime "created_at"
#t.datetime "updated_at"
t.timestamps
end
这是我创建和编辑的两个文件:
class DoNothingYet< ActiveRecord的::迁移
def up 端
确定 结束
端
类CreateUsers< ActiveRecord :: Migration
Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
端
确定 drop_table:用户 端
端
当我运行时:rake db:migrate
它不返回任何东西。当我运行rake db:migrate --trace时 我回来了:
** Invoke db:schema:load (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:schema:load
-- create_table("users", {:force=>:cascade})
-> 0.1929s
-- initialize_schema_migrations_table()
-> 0.1518s
-- create_table("users", {:force=>:cascade})
rake aborted!
Mysql2::Error: Access denied for user 'simple_cms'@'localhost' to database 'test'
/Users/john-michaelnalettenalette/simple_cms/vendor/bundle/gems/mysql2- 0.3.21/lib/mysql2/client.rb:70:in `connect'
/Users/john-michaelnalettenalette/simple_cms/vendor/bundle/gems/mysql2-0.3.21/lib/mysql2/client.rb:70:in `initialize'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:438 :in `new_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:448 :in `checkout_new_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:422 :in `acquire_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:349 :in `block in checkout'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/m onitor.rb:211:in `mon_synchronize'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:348 :in `checkout'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:263 :in `block in connection'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/m onitor.rb:211:in `mon_synchronize'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:262 :in `connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:567 :in `retrieve_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_handling.rb:87:in `connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/migration.rb:646:in `connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord-c 4.2.2/lib/active_record/migration.rb:661:in `block in method_missing'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/migration.rb:632:in `block in say_with_time'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/b enchmark.rb:281:in `measure'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/migration.rb:632:in `say_with_time'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/migration.rb:652:in `method_missing'
/Users/john-michaelnalettenalette/simple_cms/db/schema.rb:16:in `block in <top (required)>'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/schema.rb:41:in `instance_eval'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/schema.rb:41:in `define'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/schema.rb:61:in `define'
/Users/john-michaelnalettenalette/simple_cms/db/schema.rb:14:in `<top (required)>'
/Library/Ruby/Gems/2.0.0/gems/activesupport- 4.2.2/lib/active_support/dependencies.rb:268:in `load'
/Library/Ruby/Gems/2.0.0/gems/activesupport- 4.2.2/lib/active_support/dependencies.rb:268:in `block in load'
/Library/Ruby/Gems/2.0.0/gems/activesupport- 4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency'
/Library/Ruby/Gems/2.0.0/gems/activesupport- 4.2.2/lib/active_support/dependencies.rb:268:in `load'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/tasks/database_tasks.rb:218:in `load_schema_for'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/tasks/database_tasks.rb:235:in `block in load_schema_current'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/tasks/database_tasks.rb:274:in `each'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/tasks/database_tasks.rb:234:in `load_schema_current'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/railties/databases.rake:244:in `block (3 levels) in <top (required)>'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `call'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `block in execute'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `each'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `execute'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/m onitor.rb:211:in `mon_synchronize'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:173:in `invoke'
/Library/Ruby/Gems/2.0.0/gems/rake- 11.2.2/lib/rake/application.rb:152:in `invoke_task'
/Library/Ruby/Gems/2.0.0/gems/rake- 11.2.2/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `each'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `block in top_level'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:117:in `run_with_threads'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:102:in `top_level'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:80:in `block in run'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:178:in `standard_exception_handling'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:77:in `run'
/usr/bin/rake:37:in `<main>'
Tasks: TOP => db:schema:load
**调用环境 **调用db:load_config **执行db:schema:dump
当我通过我的Username- simple_cms登录mysql到我的simple_cms_development数据库时。
我尝试SHOW TABLES;
没有桌子出现。
当我运行rake db:schema:load --trace这就是我得到的:
JohnMicttesMBP5:simple_cms john-michaelnalettenalette $ rake db:schema:load --trace
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double answer = 22.0/7.0;
cout << "22.0 / 7.0 = " << fixed << setprecision(30) << answer << endl;
return 0;
}
任何建议都会受到赞赏吗?
答案 0 :(得分:0)
@ John-Michael Nalette您是否检查过database.yml中的密码对于数据库simple_cms是否正确,以及您的用户是否已登录数据库。