Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql rake数据库迁移问题_Mysql_Ruby On Rails_Migration - Fatal编程技术网

Mysql rake数据库迁移问题

Mysql rake数据库迁移问题,mysql,ruby-on-rails,migration,Mysql,Ruby On Rails,Migration,因此,我将在lynda.com上关注RubyonRails 4的基本培训。我已经进入第6章“生成迁移” 我的问题是,当我运行rake db:migrate时,我得到: == 20160918162646 CreateUsers: migrating ====================================== -- create_table(:users) rake aborted! StandardError: An error has occurred, all later

因此,我将在lynda.com上关注RubyonRails 4的基本培训。我已经进入第6章“生成迁移”

我的问题是,当我运行
rake db:migrate
时,我得到:

== 20160918162646 CreateUsers: migrating ======================================
-- create_table(:users)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `first_name` varchar(25), `last_name` varchar(50), `email` varchar(255) DEFAULT ' ' NOT NULL, `password` varchar(40), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
/Users/bryanbean/Sites/simple_cms/db/migrate/20160918162646_create_users.rb:4:in `up'
ActiveRecord::StatementInvalid: Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `first_name` varchar(25), `last_name` varchar(50), `email` varchar(255) DEFAULT ' ' NOT NULL, `password` varchar(40), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
/Users/bryanbean/Sites/simple_cms/db/migrate/20160918162646_create_users.rb:4:in `up'
Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead
/Users/bryanbean/Sites/simple_cms/db/migrate/20160918162646_create_users.rb:4:in `up'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
为什么我的数据库没有迁移

迁移文件:

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"
      t.timestamps
    end
  end

  def down
    drop_table :users 
  end

end
class CreateUsers25
t、 字符串“last_name”,:limit=>50
t、 字符串“email”,:default=>“”,:null=>false
t、 字符串“password”,:limit=>40
#t.datetime“创建时间”
#t.datetime“更新时间”
t、 时间戳
结束
结束
降下
下拉列表:用户
结束
结束

发布您的迁移文件,以便我们查看发生了什么。运行“bundle update”并再次尝试运行“rake db:migrate”,Init仍然会显示上面列出的错误。请查看:谢谢dkp!这让它发布了你的迁移文件,这样我们就可以看到发生了什么。运行“bundle update”并尝试再次运行“rake db:migrate”,Init仍然会显示上面列出的错误。请看一看:谢谢dkp!明白了