Migration to create table raises Mysql2::Error: Table doesn't exist

前端 未结 4 841
刺人心
刺人心 2020-12-30 01:17

I wrote a migration with the following:

class CreateTableSomeTable < ActiveRecord::Migration[5.1]
  def change
    create_table :some_tables do |t|
               


        
4条回答
  •  猫巷女王i
    2020-12-30 01:57

    The big issue with the ActiveRecord migration 5.1 is that now the id are expected to be BIGINT instead of INT, so when you adding a column referring another table created before rails 5.1 it expect the column type to be BIGINT but instead is just an INT, hence the error. The best solution is just modify your migration and change the type of the column to int.

    class CreateTableSomeTable < ActiveRecord::Migration[5.1]
     def change
      create_table :some_tables do |t|
       t.references :user, foreign_key: true, type: :int
       t.references :author, references: :user, foreign_key: true
       t.text :summary
      end
    end
    

    that should work.

提交回复
热议问题