Yii Framework Forum: Migration - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Migration Alter column from text to int default 0 Rate Topic: -----

#1 User is offline   hutch90 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 14-February 18

Posted 16 February 2018 - 12:29 PM

I am writing a migration that will alter a column from text to int DEFAULT 0, since all the values in that column should be numbers instead of text. The problem is that there are some values in the column that are text. When I run the following code, it gives me an error:

Code
$this->alterColumn('my_table', my_column', 'int DEFAULT 0');

Error
General error: 1366 Incorrect integer value: 'You' for column 'my_column' at row 6

I could write this migration by iterating through all of the rows and changing any text values to 0 before calling the alterColumn function, but it would be nice if there was a way to have that done automatically during the alterColumn call. Is that, or something like it, possible?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users