What's the correct syntax for remove_index in a Rails 3.1.0 migration?

后端 未结 6 899
清歌不尽
清歌不尽 2021-02-01 00:30

I\'m in the process of adding Devise to an existing Rails app, with a Users table already defined. The devise generator pushed out the following migration:

class         


        
6条回答
  •  情歌与酒
    2021-02-01 00:58

    Here is my full run of this(in Rails 5):

    I have team_id as an index in table vendors. I no longer need this relation. To get rid of it. Did the following:

    1) create the migration.

      $ rails generate migration RemoveTeam_idFromVendor team_id:integer
    

    2) Running the migration, give me this error. And that is because vendor table has rows whose foreign key references the primary key value of the team table

    == 20170727202815 RemoveTeamIdFromVendor: migrating ===========================
    -- remove_column(:vendors, :team_id, :integer)
    rake aborted!
    StandardError: An error has occurred, this and all later migrations canceled:
    
    SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE "vendors"
    

    3) To solve this and get the migration running, I did the following(Note: i am in dev):

    $ rake db:drop
    
    
    Dropped database 'db/development.sqlite3'
    Dropped database 'db/test.sqlite3'
    
    
    $ rake db:create
    Created database 'db/development.sqlite3'
    Created database 'db/test.sqlite3'
    
    $ rake db:migrate
    ~
    ~
    ~
    
    == 20170727202815 RemoveTeamIdFromVendor: migrating ===========================
    -- remove_column(:vendors, :team_id, :integer)
       -> 0.0185s
    == 20170727202815 RemoveTeamIdFromVendor: migrated (0.0185s) ==================
    

提交回复
热议问题