[RUBY] Story when migration could not be done

A story when I could not migrate due to a general mistake

  1. rails g model command
  1. rails db: migrate command
  1. Error occurrence of the main subject
  1. Temporary / Verification
  1. Solution

** 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.

rails g model command

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.

rails db: migrate command

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

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)

Temporary error / verification start

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 of Did you mean? String is It seems that there was no doubt that it was the decisive factor.

Solution

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

Story when migration could not be done
The story of stopping because the rails test could not be done
The story that the forced update could not be implemented
Note that Insert could not be done with Spring Data JDBC
[NetBeans] Story when it does not start
The story that the Servlet could not be loaded in the Java Web application
JSESSIONID could not be assigned to the URL when using Spring Security
Correspond to "error that basic authentication does not pass" in the test code "The story that could not be done"
Error: Main class not found or could not be loaded
[Java] When var should be used and when it should not be used
ERROR! MySQL server PID file could not be found!
The story that the request parameter from the iPhone application could not be obtained successfully with the Servlet
Static resources could not be distributed from WebFlux when @EnableWebFlux was granted in Spring Boot
Could not build module'nanopb'
laravel migration failed story
The story when the test folder was not created in Rails
What to check when rails db: migration does not pass