Skip to content Skip to sidebar Skip to footer

How To Add Reference Column Migration In Rails 6 With Sqlite

What is the correct way to add reference column migration in Rails 6 without getting SQLite3::SQLException: Cannot add a NOT NULL column with default value NULL? I can hack it to g

Solution 1:

By default, a foreign_key is required (on app level, not on database).

To disable, in config/application.rb add

config.active_record.belongs_to_required_by_default = false

Or

classYourModel < ApplicationRecord
  belongs_to :another_model, optional:trueend

Post a Comment for "How To Add Reference Column Migration In Rails 6 With Sqlite"