framework icon indicating copy to clipboard operation
framework copied to clipboard

[Proposal] add method to change column type in migration

Open dcrystalj opened this issue 13 years ago • 75 comments

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

dcrystalj avatar Apr 12 '13 00:04 dcrystalj

I would just drop it and then re-add it as a different type.

taylorotwell avatar Apr 13 '13 14:04 taylorotwell

@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?

iicmaster avatar Apr 13 '13 22:04 iicmaster

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!

arenowebdev avatar Apr 18 '13 17:04 arenowebdev

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.

mirkin avatar May 08 '13 19:05 mirkin

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.

schickling avatar Aug 16 '13 08:08 schickling

+1 for this. Although if you really want to you can of course (not always) just runt a query statement altering the type.

viirre avatar Oct 28 '13 12:10 viirre

+1, been battling with this for a few days now. It seems just strange there isn't a method for this.

codeclown avatar Oct 31 '13 19:10 codeclown

+1 Have to do it raw I guess

anonoz avatar Nov 12 '13 02:11 anonoz

+1 Dropping the column and adding again doesn't work in most cases.

Unprofound avatar Nov 20 '13 21:11 Unprofound

+1 Would be nice to do this with raw queries.

raleighr3 avatar Nov 21 '13 22:11 raleighr3

+1

johnnncodes avatar Dec 06 '13 01:12 johnnncodes

+1

MauMaGau avatar Dec 08 '13 22:12 MauMaGau

looks like will never see this feature :/

dcrystalj avatar Dec 09 '13 00:12 dcrystalj

https://github.com/laravel/framework/issues/895#issuecomment-16333889

This is actually quite bad

anonoz avatar Dec 09 '13 00:12 anonoz

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.

MauMaGau avatar Dec 09 '13 14:12 MauMaGau

Bump please

ctrlaltdylan avatar Dec 17 '13 04:12 ctrlaltdylan

+1 for changing column type

phirschybar avatar Jan 07 '14 20:01 phirschybar

+1 Makes definite sense for this to be possible imo

thedamon avatar Jan 09 '14 22:01 thedamon

Proposal and partial solution here #2895

MauMaGau avatar Jan 09 '14 23:01 MauMaGau

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

afroradiohead avatar Jan 11 '14 11:01 afroradiohead