My Laravel migration keeps getting error when reset/refresh :
ORA-01758: table must be empty to add mandatory (NOT NULL)
The migration is as follow:
public function up()
{
Schema::table('kasbank', function (Blueprint $table) {
$table->dropColumn('name_bn');
$table->dropColumn('id_rekon');
$table->string('name_kb')->after('kode');
$table->integer('id_rek')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('kasbank', function (Blueprint $table) {
$table->dropColumn('id_rek');
$table->dropColumn('name_kb');
$table->integer('id_rekon')->nullable();
$table->string('name_bn')->after('kode');
});
}
FYI, column id_rekon
is initially nullable in the database.
What's missed from my migration?
The problem is that your table is not empty and the current rows will be given NULL as a default value, but the column is not allowed to be NULL.
You should be able to get around it by setting a default value.
From the Oracle docs:
However, a column with a NOT NULL constraint can be added to an existing table if you give a default value; otherwise, an exception is thrown when the ALTER TABLE statement is executed.
Try:
$table->integer('id_rek')->default($value)->nullable();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.