简而言之,我开始写一个应用程序,但它不会进入生产环境,但老板喜欢它并要求我部署它。现在我必须从SQLite切换到MySQL才能将该应用程序放在生产服务器上。
我添加了gem:
迁移并没有做什么复杂的操作,它们都长得像这样:
我添加了gem:
gem' mysql2 ',〜>0.3.20'
,执行了 bundle install
,并更新了database.yml:default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password:
host: localhost
development:
<<: *default
database: umc2_dev
test:
<<: *default
database: umc2_test
production:
<<: *default
database: umc2
username: umc2
password: <%= ENV['PRODUCTION_DATABASE_PASSWORD'] %>
迁移并没有做什么复杂的操作,它们都长得像这样:
create_table :checkins do |t|
t.string :public_ip
t.string :private_ip
t.string :ubermix_version
t.string :kernel
t.string :architecture
t.integer :battery_capacity
t.integer :system_free
t.integer :home_free
t.integer :user_free
t.references :device, index: true, foreign_key: true
t.references :location, index: true, foreign_key: true
t.timestamps null: false
end
当我迁移数据库时,控制台会输出以下内容:
Mysql2::Error: Can't create table 'umc2.#sql-4e7_10' (errno: 150): \
ALTER TABLE `checkins` ADD CONSTRAINT `fk_rails_ba93b88497`
我已经为此问题苦苦思索了几个小时。我是不是漏掉了什么?我是否无意中引入了某种存储引擎的问题?MySQL 5.7.10 默认应该使用InnoDB,对吗?
SHOW CREATE TABLE checkins
的MySQL输出,以及引用表的输出,这样我们可以看到哪些已经被索引。(也可能是因为在尝试创建引用表时父表尚不存在) - undefined