vendredi 2 janvier 2015

Can I perform add and rename on a SQLite table within a single Laravel migration?

I recently added a migration to a Laravel project that I'm working on. The up method looks like this:



public function up()
{
Schema::table('payments', function(Blueprint $table)
{
$table->renameColumn('statement_description', 'statement_descriptor');
$table->string('fraud_details')->after('statement_description')->nullable();
});
}


When I run this migration on a MySQL database, it works fine. When I run my unit tests, I'm getting a table has no column named fraud_details error.


I ran a dd(\Schema::getColumnListing('payments')); in my test, and verified that the fraud_details column is not there on the SQLite testing database. However, if I comment out the renameColumn line in my migration and run the same test again, the fraud_details column appears in the list of columns.


I also experimented around with dropping the statement_description column and adding the statement_descriptor column with the fraud_details column, but the results were even worse. It doesn't throw an exception or error, but now none of the three columns I'm messing with appear on the table. Again, it works fine in my development (MySQL) environment, but not in testing (SQLite):



public function up()
{
Schema::table('payments', function(Blueprint $table)
{
$table->string('statement_descriptor')->after('statement_description')->nullable();
$table->string('fraud_details')->after('statement_description')->nullable();
$table->dropColumn('statement_description');
});
}


I can add both the statement_descriptor and fraud_details columns in a single migration, then drop the statement_description column in a subsequent migration, which is what I've done in the mean time. But I would like to know for future reference:


Is there some reason why I can't add one column and rename another within the same migration if I'm using a SQLite database?


Aucun commentaire:

Enregistrer un commentaire