[Proposal] add method to change column type in migration
It would be very nice to have it like in rails:
def self.up
change_column :my_table, :my_column, :datetime
end
def self.down
change_column :my_table, :my_column, :date
end
I would just drop it and then re-add it as a different type.
@taylorotwell if I drop it and then re-add it, I'll lost all data in that column. I think it nice to have change column type method or you have any better way to do that without losing data in the column?
I just happened to come across this too and my first thought was that you would have a changeType in there or something. However, it isn't a huge deal to me to drop and readd as I'm hopeful that I will be able to think a little bit ahead on my data structure... :) Thanks!
I need to alter a column, would be nice to do it as a migration. In my case I need to add to the list of an existing ENUM column. You may also need to change the length of a varchar or other similar cases. Dropping and recreating isn't great when you already have data in the table.
I also think droping and adding again isn't an option in production systems since all data is lost then...
@taylorotwell Which DBMS doesn't support changing the type of a column? For those you could perhaps write a little fallback function that caches all data, drops and readds the column. After that the cached data will be inserted again.
+1 for this. Although if you really want to you can of course (not always) just runt a query statement altering the type.
+1, been battling with this for a few days now. It seems just strange there isn't a method for this.
+1 Have to do it raw I guess
+1 Dropping the column and adding again doesn't work in most cases.
+1 Would be nice to do this with raw queries.
+1
+1
looks like will never see this feature :/
https://github.com/laravel/framework/issues/895#issuecomment-16333889
This is actually quite bad
Working on a little request to allow update column types here (is there a better way to present this?): https://gist.github.com/MauMaGau/7873463
A quick code review would be most welcomed.
Bump please
+1 for changing column type
+1 Makes definite sense for this to be possible imo
Proposal and partial solution here #2895
I ran into this problem a minute ago and I don't want to lose the data I've spent so hard working to get. Atm I was suggested to update it raw. But definitely would be nice to have. Like a $table->modify("column","integer",param1,param2) or something