[Ruby on Rails] NoMethodError: undefined method `t'for # <ActiveRecord :: Migration: 〇〇〇〇> Dealing with errors

Error screen![Screenshot 2020-11-15 7.34.48.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/722354/580f5a17-647e-3fbe- 38c7-99e9e4701136.png)

Corresponding source code

class AddDeviseToUsers < ActiveRecord::Migration[6.0]
  def change
    create_table :users do |t|
      t.string :name,          null: false
      t.text :profile
    end
  end
  t.string :email,              null: false, default: ''
  t.string :encrypted_password, null: false, default: ''
end

Cause

The definition of method t can only be used up to end for do in that create_table

Solution

class AddDeviseToUsers < ActiveRecord::Migration[6.0]
  def change
    create_table :users do |t|
      t.string :name,               null: false
      t.text   :profile
      #I put the bottom two lines in do
      t.string :email,              null: false, default: ''
      t.string :encrypted_password, null: false, default: ''
    end
  end
end

Supplement

If rake db: migrate is not reflected in Schema.rb, please use rake db: migrate: rollback to drop the migration and then rake db: migrate.

[Reference materials] https://qiita.com/s_tatsuki/items/3e1f119c91e21b8f0c33

Recommended Posts

[Ruby on Rails] NoMethodError: undefined method `t'for # <ActiveRecord :: Migration: 〇〇〇〇> Dealing with errors
[Ruby on Rails] NoMethodError undefined method `devise_for'error resolution
Cancel Ruby on Rails migration
[Ruby on Rails] undefined method ʻid'for nil: NilClass error resolution method
[Ruby on Rails] Convenient helper method
[Ruby on Rails] View test with RSpec
Ruby on Rails installation method [Mac edition]
Notes on using FCM with Ruby on Rails
[Ruby on Rails] Controller test with RSpec
[Ruby on Rails] Japanese notation of errors
[Ruby on Rails] Model test with RSpec
[Ruby on Rails] Follow function undefined method ʻid'for nil: NilClass error resolution
[Ruby On Rails] About RubyAws :: Sigv4 :: Errors :: MissingCredentialsError
Introducing Rspec with Ruby on Rails x Docker
Publish the app made with ruby on rails
[Rails] Procedure for linking databases with Ruby On Rails
Determine the current page with Ruby on Rails
Ruby on Rails address automatic input implementation method
[Ruby on Rails] Upload multiple images with refile
[Ruby on Rails] How to use session method
I made a portfolio with Ruby On Rails
Method summary to update multiple columns [Ruby on Rails]
[Ruby on Rails] Delete s3 images with Active Strage
Run Ruby on Rails RSpec tests with GitHub Actions
[Rails Tutorial] "NoMethodError (undefined method` activation_digest ='for # <User: 0x00000003156938>
Solve the N + 1 problem with Ruby on Rails: acts-as-taggable-on
[Environment construction Mac] Ruby on Rails (+ Webpacker handles errors)
Ruby on Rails Refactoring method example summary around MVC
[Ruby on Rails] Search function (model, method selection formula)
Created RSS / Atom format sitemap with Ruby on Rails
Ruby on Rails Elementary
Ruby on Rails basics
Ruby On Rails Association
I tried installing Ruby on Rails related plugin with vim-plug
[Ruby on Rails] Add a column with a foreign key constraint
Ruby on Rails record search, create if not find_or_create_by method
[Ruby on Rails] Implement login function by add_token_to_users with API
[Apple login] Sign in with Apple implementation procedure (Ruby on Rails)
When using Slim in Ruby on Rails, "undefined local variable or method` f'for "is displayed in form_with
Resolve ActiveRecord :: NoDatabaseError on rails6
Ruby on rails learning record -2020.10.03
Portfolio creation Ruby on Rails
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on rails learning record -2020.10.09
Ruby on Rails config configuration
Integer check method with ruby
[Ruby on Rails] about has_secure_password
Ruby on rails learning record-2020.10.07 ②
Commentary on partial! --Ruby on Rails
Ruby on rails learning record-2020.10.07 ①
[Ruby] Notes on gets method
Ruby on rails learning record -2020.10.06
Ruby on Rails validation summary
Ruby on Rails Basic Memorandum
[ruby] Method call with argument
Ruby on Rails development environment construction with Docker + VSCode (Remote Container)
Understand code coverage with Rspec, the Ruby on Rails test framework
[Ruby on Rails] Use the resources method to automatically create routes.
Steps to build a Ruby on Rails development environment with Vagrant