简体   繁体   English

Laravel迁移

[英]Laravel Migration

I created a migration: 我创建了一个迁移:

public function up()
{
    Schema::create('accounts', function(Blueprint $table) {
        $table->increments('id')->primary()->nullable(false)->index();
        $table->string('username', 32)->nullable(false)->index();
        $table->string('sha_pass_hash', 40)->nullable(false);
        $table->string('sessionkey', 80)->nullable(false);
        $table->string('v', 64)->nullable(false);
        $table->string('s', 64)->nullable(false);
        $table->string('token_key', 100)->nullable(false);
        $table->string('email', 255)->nullable(false)->unique();
        $table->timestamp('joindate')->nullable(false)->useCurrent();
        $table->string('last_ip', 15)->nullable(false)->default('127.0.0.1');
        $table->string('last_attempt_ip', 15)->nullable(false)->default('127.0.0.1');
        $table->unsignedInteger('failed_logins', 10)->nullable(false)->default(0);
        $table->unsignedTinyInteger('locked', 3)->nullable(false)->default(0);
        $table->timestamp('last_login')->nullable(false)->default('0000-00-00 00:00:00');
        $table->tinyInteger('online', 3)->nullable(false)->default(0);
        $table->unsignedTinyInteger('expansion', 3)->nullable(false)->default(6);
        $table->bigInteger('mutetime', 20)->nullable(false);
        $table->string('mutereason', 255)->nullable(false);
        $table->string('muteby', 50)->nullable(false);
        $table->unsignedTinyInteger('locale', 50)->nullable(false);
        $table->string('os', 3)->nullable(false);
        $table->unsignedInteger('recruiter', 10)->nullable(false);
        $table->unsignedInteger('battlenet_account', 10)->nullable(true)->default(NULL);
        $table->tinyInteger('battlenet_index', 3)->nullable(true)->default(NULL);
    });
}

And when i'm trying to executed command 当我试图执行命令时

php artisan migrate

I'm getting error: 我收到错误消息:

[Illuminate\Database\QueryException]                                                                                                                 
  SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'failed_logins' (SQL: create table `accounts` (`id` int unsigned   
  not null auto_increment primary key, `username` varchar(32) not null, `sha_pass_hash` varchar(40) not null, `sessionkey` varchar(80) not null, `v`   
  varchar(64) not null, `s` varchar(64) not null, `token_key` varchar(100) not null, `email` varchar(255) not null, `joindate` timestamp default CURR  
  ENT_TIMESTAMP not null, `last_ip` varchar(15) not null default '127.0.0.1', `last_attempt_ip` varchar(15) not null default '127.0.0.1', `failed_log  
  ins` int unsigned not null default '0' auto_increment primary key, `locked` tinyint unsigned not null default '0' auto_increment primary key, `last  
  _login` timestamp not null default '0000-00-00 00:00:00', `online` tinyint not null default '0' auto_increment primary key, `expansion` tinyint uns  
  igned not null default '6' auto_increment primary key, `mutetime` bigint not null auto_increment primary key, `mutereason` varchar(255) not null, `  
  muteby` varchar(50) not null, `locale` tinyint unsigned not null auto_increment primary key, `os` varchar(3) not null, `recruiter` int unsigned not  
   null auto_increment primary key, `battlenet_account` int unsigned null auto_increment primary key, `battlenet_index` tinyint null auto_increment p  
  rimary key) default character set utf8 collate utf8_unicode_ci)                                                                     


 [PDOException]                                                                                     
  SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'failed_logins' 

What i noticed is that every integer type gets auto_increment primary key in sql query. 我注意到的是,每个整数类型在sql查询中都会获得auto_increment primary key I think it could be the problem, as far as know that auto increment columns can't have default values. 我认为这可能是问题所在,据我所知自动递增列不能具有默认值。

If you take a look at the source code for the unsignedInteger method, you'll notice the second parameter doesn't specify length, but rather is for an autoIncrement boolean. 如果您查看unsignedInteger方法的源代码 ,您会注意到第二个参数没有指定长度,而是为一个autoIncrement布尔值。 You'll need to update your various integer methods accordingly. 您需要相应地更新各种整数方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM