我最初使用PostgreSQL开发了我的rails 5应用程序。由于托管方面的一些问题,我完成了所有开发工作后,我不得不转换到MariaDB。
我正在尝试添加一个更新,从我的购物车中添加对管理员的引用。这是我的迁移:
class AddAdminRefToCart < ActiveRecord::Migration[5.1]
def change
add_reference :carts, :admin, foreign_key: true
end
end
当我跑
时rake db:migrate
我收到此错误:
== 20171129152942 AddAdminRefToCart: migrating ================================
-- add_reference(:carts, :admin, {:foreign_key=>true})
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
Column `admin_id` on table `carts` has a type of `bigint(20)`.
This does not match column `id` on `admins`, which has type `int(11)`.
To resolve this issue, change the type of the `admin_id` column on `carts` to be :integer. (For example `t.integer admin_id`).
错误有意义,但我不确定解决问题的正确方法。有人可以就如何编写我的迁移提供一些指导吗?提前谢谢!