alnahian2003's avatar

$table->after() not working in database migration!

Hey, I'm running a latest laravel 9 application on my local machine. According to the official db migrations doc , I can move a column of a table using the after() method.

Currently I have a posts table in my sqlite3 database and I want to add a new column named 'views' in it. So I normally ran the migration command and in the migration file, I added $table->bigInteger('views')->after('cover')->default(0); line inside the up() method (also provided convenient stuffs to reverse the migration in the down() method). So after running the php artisan migrate command, and checking the table, I realized that the views column has been created but in wrong order, in the usual order, I mean at the end of the table.

After testing and performing the same process for couple times, I still ain't got no solution or idea that, why it isn't working!

Is that because I'm using sqlite? πŸ˜‘πŸ˜‘πŸ˜‘ How can I solve this problem and order my column as I want?

N.B. (Doctrine/Dbal already installed through composer)

Thank You!

0 likes
7 replies
alnahian2003's avatar

@tykus Urrrgh... Exactly what I suspected! πŸ˜Άβ€πŸŒ«οΈ Thanks for your answer.

Btw, I dunno maybe it gives me inner peace ordering the columns sometimes. Or maybe pleasure for eyes πŸ‘€

1 like
tykus's avatar

@alnahian2003 really it's not important. TBH I rarely am looking at a DB GUI anymore so I don't feel that pain very often.

1 like
alnahian2003's avatar

@Sinnbeck Aha! Seems like sqlite has many restrictions πŸ˜‘

ALRIGHT, Thanks a lot. It was kinda out of the box thing for me

martinbean's avatar

Seems like sqlite has many restrictions

@alnahian2003 Not restrictions, but the clue is in the name: sqlite

2 likes
Snapey's avatar

And obviously this only applies to on-going maintenance migrations. Otherwise, go back to your earlier migrations, amend them and rebuild the database.

3 likes

Please or to participate in this conversation.