[英]Laravel 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);
});
}
當我試圖執行命令時
php artisan migrate
我收到錯誤消息:
[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'
我注意到的是,每個整數類型在sql查詢中都會獲得auto_increment primary key
。 我認為這可能是問題所在,據我所知自動遞增列不能具有默認值。
如果您查看unsignedInteger
方法的源代碼 ,您會注意到第二個參數沒有指定長度,而是為一個autoIncrement
布爾值。 您需要相應地更新各種整數方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.