我正在尝试运行在 Laravel 5.2 版本上完美运行的迁移,但是当我尝试在 Laravel 5.5 上运行它时,出现错误:
In Connection.php line 664:
SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'to_date' (SQL: create table
transactions
(id
int unsigned not null auto_increment primary key,user_id
int unsigned not null,vehicle_id
int unsigned not null,from_date
t
imestamp not null,to_date
timestamp not null,flight_number
varchar(255) not null,created_at
timestamp null,updated_at
ti
mestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)In Connection.php line 458: SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'to_date'
这是该表的迁移:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTransactionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('transactions', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->integer('vehicle_id')->unsigned();
$table->foreign('vehicle_id')->references('id')->on('vehicles');
$table->timestamp('from_date');
$table->timestamp('to_date');
$table->string('flight_number');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('transactions');
}
}
为什么在 5.2 上运行时不能在新版本的 laravel 上运行?
最佳答案
我找到了导致问题的原因,在 laravel 5.5 中 MySQL 在 laravel config 中启用了严格模式 database.php
文件默认情况下,通过将模式设置为 'strict' => false
,就像在 5.3 版本中一样,我可以运行迁移。
关于mysql - Laravel 5.5 - 迁移不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48169317/