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
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.
Most helpful comment
This error usually means there are NULL values in the table and the database cannot be altered until they are removed.