Framework: Can't remove nullable in migration

Created on 17 Dec 2015  路  5Comments  路  Source: laravel/framework

I can add nullable flag to a column:

    public function up()
    {
        Schema::table('table, function(Blueprint $table) {
            $table->integer('some')->nullable()->change();
        });
    }

but rollback won't work:

    public function down()
    {
        Schema::table('table', function(Blueprint $table) {
            $table->integer('some')->change();
        });
    }

after rollback the column will be still nullable

Most helpful comment

This error usually means there are NULL values in the table and the database cannot be altered until they are removed.

All 5 comments

You can use nullable(false) to remove nullable.

public function down()
{
    Schema::table('table', function(Blueprint $table) {
        $table->integer('some')->nullable(false)->change();
    });
}

thanks

I'm getting error:

[Illuminate\Database\QueryException]
SQLSTATE[22004]: Null value not allowed: 1138 Invalid use of NULL value (SQL: ALTER TABLE users CHANGE email email VARCHAR(255) NOT NULL COLLATE utf8mb4_unicode_ci, CHANGE password password VARCHAR(255) NOT NULL COLLATE utf8mb4_unicode_ci)

[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[22004]: Null value not allowed: 1138 Invalid use of NULL value

[PDOException]
SQLSTATE[22004]: Null value not allowed: 1138 Invalid use of NULL value

My migration code:

// OK
public function up()
{
    Schema::table('users', function (Blueprint $table) {
        $table->string('email')->nullable()->change();
        $table->string('password')->nullable()->change();
    });
}

// Fail
public function down()
{
    Schema::table('users', function (Blueprint $table) {
        $table->string('email')->nullable(false)->change();
        $table->string('password')->nullable(false)->change();
    });
}

What's wrong?

notNull() gives the same error

This error usually means there are NULL values in the table and the database cannot be altered until they are removed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

klimentLambevski picture klimentLambevski  路  3Comments

felixsanz picture felixsanz  路  3Comments

shopblocks picture shopblocks  路  3Comments

JamborJan picture JamborJan  路  3Comments

kerbylav picture kerbylav  路  3Comments