简体   繁体   English

Oracle数据库上的Laravel迁移重置/刷新错误ORA-01758

[英]Laravel migration reset/refresh error ORA-01758 on Oracle Database

My Laravel migration keeps getting error when reset/refresh : 我的Laravel迁移在重置/刷新时不断出错:

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. 仅供参考, id_rekon列最初在数据库中id_rekon为空。

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. 问题在于您的表不为空,并且当前行将被赋予NULL作为默认值,但是该列不允许为NULL。

You should be able to get around it by setting a default value. 您应该可以通过设置默认值来解决它。

From the Oracle docs: 从Oracle文档:

However, a column with a NOT NULL constraint can be added to an existing table if you give a default value; 但是,如果提供默认值,则可以将具有NOT NULL约束的列添加到现有表中。 otherwise, an exception is thrown when the ALTER TABLE statement is executed. 否则,执行ALTER TABLE语句时将引发异常。

Try: 尝试:

$table->integer('id_rek')->default($value)->nullable();

From: https://laravel.com/docs/5.5/migrations 来自: https : //laravel.com/docs/5.5/migrations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM