What is :cascade in rails schema.rb and where did it come from?

Ruby on-Rails

Ruby 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

http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-create_table

:force Set to true to drop the table before creating it. Set to :cascade to drop dependent objects as well. Defaults to false.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkirqeView Question on Stackoverflow
Solution 1 - Ruby on-RailsAndrew HubbsView Answer on Stackoverflow
Solution 2 - Ruby on-RailsLaneView Answer on Stackoverflow