What is :cascade in rails schema.rb and where did it come from?
Ruby on-RailsRuby on-Rails Problem Overview
After adding another migration and occasional decision to drop and migrate I checked my schema.rb and saw this
create_table "users", force: :cascade do |t|
I haven't committed this changes yet and on remote I have this
create_table "users", force: true do |t|
Now I have cascade in front of each table. What is cascade and where did it come from?
Ruby on-Rails Solutions
Solution 1 - Ruby on-Rails
The docs explain what :cascade
does:
> :force
- Set to :cascade
to drop dependent objects as well. Defaults to false
.
One reason you may be seeing this is a change in Rails 4.2 in SchemaDumper
to use :cascade
, release notes.
Release notes about change:
> SchemaDumper
uses force: :cascade
on create_table
. This makes it possible to reload a schema when foreign keys are in place.
Solution 2 - Ruby on-Rails
:force
Set to true
to drop the table before creating it. Set to :cascade
to drop dependent objects as well. Defaults to false
.