Reputation: 136
I want to simply rename my one column although it keeps saying
SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'sendReminderCouple48' (SQL: ALTER TABLE sendIntakes CHANGE sendReminderCouple36 sendReminderCouple48 DATETIME DE
FAULT 'NULL')
Currently its sendReminderCouple36
- DATETIME
- NULLABLE
All I want to do is rename it to sendReminderCouple48
public function up()
{
Schema::table('sendIntakes', function (Blueprint $table) {
$table->renameColumn('sendReminderCouple36', 'sendReminderCouple48');
});
}
public function down()
{
Schema::table('sendIntakes', function (Blueprint $table) {
$table->renameColumn('sendReminderCouple48', 'sendReminderCouple36');
});
}
Note: I do not want to do any strict changes in my config file.
Upvotes: 1
Views: 131
Reputation: 136
I fixed it by changing the type to a text - rename - then back to date time
public function up()
{
Schema::table('sendIntakes', function (Blueprint $table) {
$table->text('sendReminderCouple36')->default(null)->nullable()->change();
});
Schema::table('sendIntakes', function (Blueprint $table) {
$table->renameColumn('sendReminderCouple36', 'sendReminderCouple48');
});
Schema::table('sendIntakes', function (Blueprint $table) {
$table->datetime('sendReminderCouple48')->default(null)->nullable()->change();
});
}
public function down()
{
Schema::table('sendIntakes', function (Blueprint $table) {
$table->text('sendReminderCouple48')->default(null)->nullable()->change();
});
Schema::table('sendIntakes', function (Blueprint $table) {
$table->renameColumn('sendReminderCouple48', 'sendReminderCouple36');
});
Schema::table('sendIntakes', function (Blueprint $table) {
$table->datetime('sendReminderCouple36')->default(null)->nullable()->change();
});
}
Upvotes: 0
Reputation: 2229
This is probably related to issue #22050 on the Laravel framework. Are you running MariaDB as your database engine?
Following the advice in the thread, you might try changing the default value on the column before doing the rename call:
Schema::table('products', function (Blueprint $table) {
$table->string('name')->default(null)->change();
});
Schema::table('products', function (Blueprint $table) {
$table->renameColumn('name', 'description');
});
Schema::table('products', function (Blueprint $table) {
$table->string('description')->default(null)->change();
});
Upvotes: 1