Migration - Enter Columns before created_at and updated_at columns
Is there a way to always enter columns before the created_at column in migrations? The only option I know of is the after clause but then the name of the previous column in the DB has to be entered.
Hi guys, the laravel command ->after('column') inserts a column after a specified one in a migration. I am looking for the opposite i.e. to enter a column previous to or before another column.
Well I already have other columns, which is why I asked if a 'before' exists. I could definitely do that yes but if a 'before' existed it would have been easier to always insert them before the created_at, not having to check what was previous to.
Sadly I dont think mysql supports BEFORE in an alter statement, so that is most likely why it does not exist. It would need some "hacks" to first find the column before doing the migration then.
Third, MySQL allows you to add the new column as the first column of the table by specifying the FIRST
keyword. It also allows you to add the new column after an existing column using the AFTER existing_column
clause. If you don’t explicitly specify the position of the new column, MySQL will add it as the last column.