When you create a new column in a table you can use the ->after('column name') to dictate where it goes. How can I create a migration that re-orders the columns in the right order I want?
相关问题
- Laravel Option Select - Default Issue
- How to execute MYSQL query in laravel?
- can't use paginate when use sortby in Laravel
- Do [DataType(DataType.EmailAddress)] have a counte
- How to use advanced where clause while using OR op
相关文章
- php : The term 'php' is not recognized as
- Laravel hasMany detach
- Laravel Eloquent, select only rows where the relat
- How Do I Seed My Database in the setupBeforeClass
- SQLSTATE[HY000] [2002] Permission denied
- Warning: failed to open stream: No such file or di
- Attaching a hasOne model to another Laravel/Eloque
- Clear Laravel's orderBy
If you want to do it without destroying data, you could migrate the data across at the same time you do the schema update:
Very Important Note
Use the following solution only if you still in the development phase and you haven't launched your app yet as the following solution will delete the column and all data stored in it and will create a new empty column with the same name after the column you determine.
Suppose your column name is
address
and you want to reorder its position so that it comes after another column calledcity
, and your table name isemployees
.In your terminal type the next command:
You may only change
reorganize_order_of_column_address
andemployees
according to your needs, but keep the rest of the command as it is.This will generate a migration file in
app/database/migrations
folder, open it and put your code inside theup()
function like this:I would suggest a DB::query('.. raw sql query ..'); and use the query from the answer "How to move columns in a MySQL table?"
Try this, hope it help you to find right solution: