実現したいこと
参考書を見ながらオリジナルアプリ開発途中、テーブル内に不備があったためモデルとマイグレーションファイルを削除してから作り直すことにしました。
やったこと
マイグレーションファイルのステータスを確認してダウン、削除
モデルもdocker-compose run web rails destroy model userで削除
その後
docker-compose run web rails g model user schoolname:string email:string address:string telephonenumber:string password_digest:string
上記コードでモデルとマイグレーションファイル作成
モデル class User < ApplicationRecord has_secure_password validates :schoolname, presence: true, uniqueness: true validates :email, presence: true, uniqueness: true validates :address, presence: true, uniqueness: true validates :telephonenumber, presence: true, uniqueness: true has_many :tweets, dependent: :destroy end
マイグレーションファイル class CreateUsers < ActiveRecord::Migration[6.1] def change create_table :users do |t| t.string :schoolname, null: false t.string :email, null: false t.string :address, null: false t.string :telephonenumber, null: false t.string :password_digest, null: false t.timestamps t.index :schoolname, email, address, telephonenumber, unique: true end end end
作成後、上記の内容に編集してマイグレートを実行すると以下のエラーが出てきます。
undefined local variable or method `email' for #<CreateUsers:0x0000555f6cf200c8 @name="CreateUsers", @version=20220208091654, @connection=nil> NameError: undefined local variable or method `email' for #<CreateUsers:0x0000555f6cf200c8 @name="CreateUsers", @version=20220208091654, @connection=nil>
2つのエラー文について色々調べてみましたがよく分からず、email未定義となっていますが具体的にどうしたら良いのかも分かりません。
どなたかアドバイスお願いします。
開発環境
dockerファイル
From ruby:3.0.1 RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \ && apt-get update -qq \ && apt-get install -y nodejs yarn mariadb-client WORKDIR /app COPY ./src /app RUN bundle config --local set path 'vendor/bundle' \ && bundle install
docker-compose.yml
version: '3.0' services: db: image: mysql:8.0.27 command: --default-authentication-plugin=mysql_native_password volumes: - ./src/db/mysql_data:/var/lib/mysql environment: MYSQL_ROOT_PASSWORD: password web: build: . command: bundle exec rails s -p 3000 -b '0.0.0.0' volumes: - ./src:/app ports: - "3000:3000" depends_on: - db
gemfile
source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '3.0.1' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' gem 'rails', '~> 6.1.4', '>= 6.1.4.1' # Use mysql as the database for Active Record gem 'mysql2', '~> 0.5' # Use Puma as the app server gem 'puma', '~> 5.0' # Use SCSS for stylesheets gem 'sass-rails', '>= 6' # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker gem 'webpacker', '~> 5.0' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.7' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 4.0' # Use Active Model has_secure_password gem 'bcrypt', '~> 3.1.7' # Use Active Storage variant # gem 'image_processing', '~> 1.2' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.4', require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. gem 'web-console', '>= 4.1.0' # Display performance information such as SQL time and flame graphs for each request in your browser. # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md gem 'rack-mini-profiler', '~> 2.0' gem 'listen', '~> 3.3' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end group :test do # Adds support for Capybara system testing and selenium driver gem 'capybara', '>= 3.26' gem 'selenium-webdriver' # Easy installation and use of web drivers to run system tests with browsers gem 'webdrivers' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'slim-rails' gem 'html2slim' gem 'bootstrap' gem 'ransack' gem 'kaminari'
文字数オーバーで正確なエラー内容を伝えることができなかったので画像で追加します。
https://gyazo.com/1a64a8251a5e0994b19d77783ece535a
https://gyazo.com/2b193dc7b004af5fca21e596368432e1
回答1件
あなたの回答
tips
プレビュー