【发布时间】:2020-01-17 20:46:29
【问题描述】:
对于一个非常旧的迁移(过去运行良好),我遇到了一个新的迁移错误。
我得到的错误是:SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHARACTER SET utf8 NOT NULL COLLATE `utf8_unicode_ci`' at line 1 (SQL: ALTER TABLE rooms CHANGE conversion conversion TINYINT(1) CHARACTER SET utf8 NOT NULL COLLATE `utf8_unicode_ci`)
迁移文件如下所示:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ChangeRoomsConversionToBoolean extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('rooms', function (Blueprint $table) {
$table->boolean('conversion')->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('rooms', function (Blueprint $table) {
$table->string('conversion')->change();
});
}
}
如果我直接在数据库ALTER TABLE rooms CHANGE conversion conversion TINYINT(1) CHARACTER SET utf8 NOT NULL COLLATE `utf8_unicode_ci` 中运行查询,则会收到错误:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHARACTER SET utf8 NOT NULL' at line 1
我正在使用 Laravel 5.6 在 Homestead 上运行。
任何帮助将不胜感激。
【问题讨论】:
标签: php mysql laravel laravel-5.6