更改列类型 Laravel 5
Change column type Laravel 5
为什么会出现以下错误
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 'NOT NULL
COLLATE utf8mb4_unicode_ci' at line 1 (SQL: ALTER TABLE questions CHANGE category_id category_id INT DEFAULT NOT NULL COLLATE utf8mb4_unicode_ci)
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 'NOT NULL
COLLATE utf8mb4_unicode_ci' at line 1
通过执行以下代码:
Schema::table('questions', function(Blueprint $table) {
$table->integer('category_id')->unsigned()->change();
});
改用unsignedInteger
Schema::table('questions', function(Blueprint $table) {
$table->unsignedInteger('category_id')->change();
});
为什么会出现以下错误
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 'NOT NULL
COLLATE utf8mb4_unicode_ci' at line 1 (SQL: ALTER TABLE questions CHANGE category_id category_id INT DEFAULT NOT NULL COLLATE utf8mb4_unicode_ci)
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 'NOT NULL
COLLATE utf8mb4_unicode_ci' at line 1
通过执行以下代码:
Schema::table('questions', function(Blueprint $table) {
$table->integer('category_id')->unsigned()->change();
});
改用unsignedInteger
Schema::table('questions', function(Blueprint $table) {
$table->unsignedInteger('category_id')->change();
});