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?
It is a Ruby representation of your database; schema. rb is created by inspecting the database and expressing its structure using Ruby.
The schema. rb serves mainly two purposes: It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduce the schema just from the migrations alone. With a present schema.
You must rollback the migration (for example with bin/rails db:rollback ), edit your migration, and then run bin/rails db:migrate to run the corrected version.
A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.
The docs explain what :cascade
does:
:force
- Set to:cascade
to drop dependent objects as well. Defaults tofalse
.
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
usesforce: :cascade
oncreate_table
. This makes it possible to reload a schema when foreign keys are in place.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With