Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Migrations: tried to change the type of column from string to integer
    primarykey
    data
    text
    <p>I created a table in my rails app with rails generate migrations command. Here is that migration file:</p> <pre><code>class CreateListings &lt; ActiveRecord::Migration def change create_table :listings do |t| t.string :name t.string :telephone t.string :latitude t.string :longitude t.timestamps end end end </code></pre> <p>Then I wanted to store the latitude and longitude as integers so I tried to run:</p> <pre><code>rails generate migration changeColumnType </code></pre> <p>and the contents of that file are:</p> <pre><code>class ChangeColumnType &lt; ActiveRecord::Migration def up #change latitude columntype from string to integertype change_column :listings, :latitude, :integer change_column :listings, :longitude, :integer #change longitude columntype from string to integer type end def down end end </code></pre> <p>I was expecting the column type to change however the rake was aborted and the following error message appeared. I was wondering why this did not go through? Im using postgresql in my app.</p> <pre><code>rake db:migrate == ChangeColumnType: migrating =============================================== -- change_column(:listings, :latitude, :integer) rake aborted! An error has occurred, this and all later migrations canceled: PG::Error: ERROR: column "latitude" cannot be cast to type integer : ALTER TABLE "listings" ALTER COLUMN "latitude" TYPE integer Tasks: TOP =&gt; db:migrate (See full trace by running task with --trace) </code></pre> <p>NOTE: The table has no DATA. Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload