Reputation: 91
I cannot execute migrate:fresh.
Command fails at changing table column from:
$table->string('language_id')->default('')->length(255);
to:
$table->integer('language_id')->unsigned()->default(1)->change();
Error that I'm getting:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CHARACTER SET utf8mb4 DEFAULT 1 NOT N ULL COLLATE
utf8mb4_unicode_ci
' at line 1 (SQL: ALTER TABLE users CHANGE language_id language_id INT UNSIGNED CHA RACTER SET utf8mb4 DEFAULT 1 NOT NULL COLLATEutf8mb4_unicode_ci
)
Any help/hints would be appreciated.
Upvotes: 1
Views: 2684
Reputation: 3702
Need doctrine/dbal
composer require doctrine/dbal
write a new migration & write this
public function up()
{
Schema::table('table_name', function (Blueprint $table) {
$table->integer('language_id')->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('your_table_name', function (Blueprint $table) {
$table->dropColumn('language_id');
});
}
Upvotes: 1
Reputation: 629
If the standard solution is not working. You can try this:
public function up()
{
DB::statement('ALTER TABLE mytable MODIFY mycolumn INTEGER;');
}
public function down()
{
DB::statement('ALTER TABLE mytable MODIFY mycolumn STRING;');
}
Upvotes: 2
Reputation: 461
Depending on the Laravel Documentation:
Note: Before changing a column, be sure to add the doctrine/dbal dependency to your composer.json file.
Try this
Schema::table('your_table_name', function (Blueprint $table) {
$table->unsignedInteger('language_id')->default(1);
});
Upvotes: 0