I seem to remember reading somewhere that ->after wasn't supported by SQLite so try removing it and just place the column last.
Nov 15, 2021
3
Level 6
During Testing Only: SQLSTATE[42S22]: Column not found: 1054 Unknown column
I have a migration where I add a column to a table like so:
public function up()
{
Schema::table('applications', function (Blueprint $table) {
$table->string('state')->after('template_id')->default(''); // in progress, in review, etc.
$table->index(['team_id'], 'app_team_idx');
});
}
public function down()
{
Schema::table('applications', function (Blueprint $table) {
$table->dropIndex('app_team_idx');
});
Schema::table('applications', function (Blueprint $table) {
$table->dropColumn('state');
});
}
During my tests, I run an artisan db:seed command. Half way through this seed, It updates the "state" field in an application. However it fails with:
Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'state' in 'field list' (SQL: update `applications` set `state` = dr, `applications`.`updated_at` = 2021-11-15 14:28:56 w
here `id` = 2)
I added a saving event listener on the model and printed the columns available in the table. The 'state' column is present, so I can only imagine this has something to do with the mysql & sqlite difference during testing. Usually it's a problem with the actual migration, but this shows the column exists. So what's happening?
static::saving(function($app) {
$table = $app->getTable();
$columns = Schema::getColumnListing($table);
var_dump($columns);
});
Please or to participate in this conversation.