Hi guys,
So I have a table with clients. Each client has a name and an email and so on. We first decided that the email was required. Now we don't want that anymore and the column needs to be nullable. To do this we use a migration of course .
create_clients_table migration
class CreateClientsTable extends Migration {
public function up()
{
Schema::create('clients', function(Blueprint $table)
{
$table->increments('id');
$table->string('sc_number')->unique();
$table->string('name');
$table->string('email');
$table->string('status');
$table->timestamps();
$table->softDeletes();
});
}
}
update_clients_email_to_nullable migration
class UpdateClientEmailToNullable extends Migration {
public function up()
{
DB::statement('ALTER TABLE clients MODIFY email VARCHAR(255) DEFAULT NULL;');
}
}
This is all working fine with mysql. However I use the same migrations for testing. I use an sqlite database for this. When I run the migration I get this error:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1 near "MODIFY": syntax error (SQL: ALTER TABLE clients MODIFY email VARCHAR(255) DEFAULT NULL;)
[PDOException]
SQLSTATE[HY000]: General error: 1 near "MODIFY": syntax error
One solution would be to clear my database and change the first migration and add the nullable attribute. Since this project is running on a production server I don't want to do this. This will delete all data! The best way would be a migration!
Any thought would be welcome :D