Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a migration, how do you change the column type to text without specifying the :limit?

I want to change a column type from :string to :text

The problem is that if I simply do:

change_column :questions, :content, :text

Then the schema is rewritten to:

t.string   "content",     :limit => 255

i.e. it takes the length that was implicit when it was a string

How can I do the migration and specify that the :limit should not be set such that the schema reads:

t.string   "content"

I have tried setting an arbitrary limit of 10,000 but a) that feels inefficient and b) it makes the down migration attempt to set the :text limit to 10,000.

What option can I pass to the change_column method to ensure it simply uses the default limit?

like image 374
Peter Nixey Avatar asked Jul 14 '11 11:07

Peter Nixey


People also ask

How do I change the column type in Sequelize migration?

Supposing that the column was of type DataTypes. STRING , we would do: await queryInterface. changeColumn('User', 'ip', { type: Sequelize.

How do I change the column type in postgresql?

First, specify the name of the table to which the column you want to change belongs in the ALTER TABLE clause. Second, give the name of column whose data type will be changed in the ALTER COLUMN clause. Third, provide the new data type for the column after the TYPE keyword.


1 Answers

Ack, discovered this by trial and error moments after posting the question:

change_column :questions, :content, :text, :limit => nil
like image 83
Peter Nixey Avatar answered Oct 24 '22 06:10

Peter Nixey