** We will proceed with the above 5-stage configuration. ** **
If you are in a hurry to the main subject Please fly from Error occurrence of the main subject. After that, we will proceed with some supplements.
When you create a model with the rails g model command
A migration file is generated at the same time in the db/migrate/directory
.
The contents of the migration file look like this
db/migrate/20XXXXXXXXXXXX_create_Plural model name.rb
class Create Plural of model name< ActiveRecord::Migration[6.0]
def change
create_table :Model name plural do|t|
t.timestamps
end
end
end
% rails g model singular model name
Abbreviation for generate, which means to generate. Basically, the controller name is plural and the model name is the singular of the corresponding word.
Supplementary information:
% rails d model Singular model name Abbreviation for
destroy, which means to delete.
Specify the column type and column name
that you want to save in the database in the migration file,
The flow is to type % rails db: migrate
and execute migration ...
% rails db:migrate
This behavior is sometimes referred to as migration.
Migration cannot be executed and the following error statement is displayed in the terminal ...
== 20210119052352 CreateAddresses: migrating ==================================
-- create_table(:addresses)
rails aborted!
StandardError: An error has occurred, all later migrations canceled:
undefined method `steing' for #<ActiveRecord::ConnectionAdapters::MySQL::TableDefinition:0x00007fbc8955f760>
Did you mean? string
~~abridgement~~
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Caused by:
NoMethodError: undefined method `steing' for #<ActiveRecord::ConnectionAdapters::MySQL::TableDefinition:0x00007fbc8955f760>
NoMethodError: undefined method `steing'
~~abridgement~~
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
It came out for a long time, but at present I focused on the following three points
1. StandardError: An error has occurred, all later migrations canceled:`
2. undefined method `steing' for #
3. Did you mean? string
The possibility of spelling mistakes has emerged due to the fact that I made a mistake when specifying the column type.
I didn't pursue it, but also for the above error statement that says Standard Error
I'm curious when I organize it in this way.
Search results:
rails db: migrate: reset
I found an article that solved the error by resetting the database. However, in this case, the notation ofDid you mean? String
is It seems that there was no doubt that it was the decisive factor.
After this, I reviewed the migration file and found steing
as expected.
==20210119052352 Create model name plural: migrating ==================================
-- create_table(:Plurale of model name)
-> 0.3171s
== 20210119052352 CreateAddresses: migrated (0.3174s) =========================
Successfully migrated
If the column name was wrong, it would have rolled back without throwing an error.
Recommended Posts