Mysql RubyonRails:数据类型外键
我有以下表格:Mysql RubyonRails:数据类型外键,mysql,ruby-on-rails,ruby,database,ruby-on-rails-4,Mysql,Ruby On Rails,Ruby,Database,Ruby On Rails 4,我有以下表格: 具有主键ID的路由(ID、名称) 主键ID为的停止(ID、名称) 映射(路线ID、站点ID) Route和Stop中的ID在myMySQL数据库中的类型是BIGINT(20)。迁移失败,因为使用以下方法: class CreateMappings < ActiveRecord::Migration def change create_table :mappings do |t| t.references :route, index: true, foreig
- 具有主键ID的路由(ID、名称)
- 主键ID为的停止(ID、名称)
- 映射(路线ID、站点ID)
class CreateMappings < ActiveRecord::Migration
def change
create_table :mappings do |t|
t.references :route, index: true, foreign_key: true
t.references :stop, index: true, foreign_key: true
t.timestamps null: false
end
end
end
你试过这个表格吗
class CreateMappings < ActiveRecord::Migration
def change
create_table :mappings do |t|
t.references :route
t.references :stop
t.timestamps null: false
end
end
add_index(:mappings, :route)
add_index(:mappings, :stop)
end
class CreateMappings
例如,如果您不希望添加的列是整数,则references
方法将采用类型选项
t.references :route, type: :bigint, index: true, foreign_key: true
错误消息是什么?将其添加到问题中。这没有帮助,因为路由的结果数据类型将是int而不是bigint
t.references :route, type: :bigint, index: true, foreign_key: true