我只是想在现有表中添加新列。这是我的迁移:
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddWarehouse extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('routes', function (Blueprint $table){
$table->string('warehouse_address');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('routes', function (Blueprint $table){
$table->dropColumn(['warehouse_address']);
});
}
}
运行php artisan migrate会导致以下错误:
[Illuminate\Database\QueryException]
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00' for column 'created_at' at row 1 (SQL: alter table `routes` add `warehouse_address` varchar(255) not null)
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00' for column 'created_at' at row 1
[PDOException]
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00' for column 'created_at' at row 1
该表包含已填充正确值的“created_at”和“updated_at”列。如何阻止Schema尝试将日期时间插入“created_at”列?我宁愿不管它。
在MySql中执行命令非常正常。
编辑:当我尝试在没有“created_at”和“updated_at”列的表上运行相同的迁移时,我收到同样的错误。
答案 0 :(得分:0)
在您的路线模型中放置public $timestamps = false;
将阻止Eloquent尝试更新它们。