ruby-on-rails-4.2

Add nullable foreign key in Rails

心不动则不痛 提交于 2019-11-27 14:19:37
问题 Referencing to Rails 4.2 add_foreign_key support: # add a foreign key to `articles.author_id` referencing `authors.id` add_foreign_key :articles, :authors How to create a nullable foreign key constraint, to allow the situation, where articles.author_id can be sometimes null? 回答1: There is nothing in the guide that implies add_foreign_key would make the corresponding foreign field "NOT NULL" or required. add_foreign_key simply adds a foreign key constraint whether the field is required or not

Rails 4 - Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded

血红的双手。 提交于 2019-11-26 15:11:55
问题 In my gemfile I have: gem 'mysql2' My database.yml is as follows: default: &default adapter: mysql2 database: <%= ENV['db_name'] %> username: <%= ENV['db_user'] %> password: <%= ENV['db_pass'] %> host: <%= ENV['db_host'] %> pool: 32 socket: <%= ENV['socket'] %> development: <<: *default production: <<: *default I've run both bundle update and bundle install and my Gemfile.lock shows mysql2. However when I run rake db:migrate I get this on both my computer and on the staging server: myproject