解決したいこと
データベースを作成させたい
ターミナルエラー文
niimurakenta@mba union-app % rails db:migrate
== 20210128012551 CreateEntries: migrating ====================================
-- create_table(:entries)
rails aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Table 'union_app_development.users' doesn't exist
/Users/niimurakenta/projects/union-app/db/migrate/20210128012551_create_entries.rb:3:in change' /Users/niimurakenta/projects/union-app/bin/rails:9:in
<top (required)>'
/Users/niimurakenta/projects/union-app/bin/spring:15:in <top (required)>' bin/rails:3:in
load'
bin/rails:3:in `<main>'
Caused by:
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'union_app_development.users' doesn't exist
/Users/niimurakenta/projects/union-app/db/migrate/20210128012551_create_entries.rb:3:in change' /Users/niimurakenta/projects/union-app/bin/rails:9:in
<top (required)>'
/Users/niimurakenta/projects/union-app/bin/spring:15:in <top (required)>' bin/rails:3:in
load'
bin/rails:3:in `<main>'
Caused by:
Mysql2::Error: Table 'union_app_development.users' doesn't exist
/Users/niimurakenta/projects/union-app/db/migrate/20210128012551_create_entries.rb:3:in change' /Users/niimurakenta/projects/union-app/bin/rails:9:in
<top (required)>'
/Users/niimurakenta/projects/union-app/bin/spring:15:in <top (required)>' bin/rails:3:in
load'
bin/rails:3:in `<main>'
Caused by:
Mysql2::Error: Cannot add foreign key constraint
/Users/niimurakenta/projects/union-app/db/migrate/20210128012551_create_entries.rb:3:in change' /Users/niimurakenta/projects/union-app/bin/rails:9:in
<top (required)>'
/Users/niimurakenta/projects/union-app/bin/spring:15:in <top (required)>' bin/rails:3:in
load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
コード
ruby
1class CreateRooms < ActiveRecord::Migration[6.0] 2 def change 3 create_table :rooms do |t| 4 t.string :name 5 6 t.timestamps 7 end 8 end 9end 10
ruby
1class CreateEntries < ActiveRecord::Migration[6.0] 2 def change 3 create_table :entries do |t| 4 t.references :user, null: false, foreign_key: true 5 t.references :room, null: false, foreign_key: true 6 t.integer :profile_id 7 t.timestamps 8 end 9 end 10end
ruby
1class CreateMessages < ActiveRecord::Migration[6.0] 2 def change 3 create_table :messages do |t| 4 t.references :user, null: false, foreign_key: true 5 t.references :room, null: false, foreign_key: true 6 t.text :content 7 t.references :profile, null: false, foreign_key: true 8 t.timestamps 9 end 10 end 11end
ruby
1# frozen_string_literal: true 2 3class DeviseCreateUsers < ActiveRecord::Migration[6.0] 4 def change 5 create_table :users do |t| 6 ## Database authenticatable 7 t.string :nickname, null: false 8 t.string :email, null: false, default: "" 9 t.string :encrypted_password, null: false, default: "" 10 t.date :birthday, null: false 11 12 ## Recoverable 13 t.string :reset_password_token 14 t.datetime :reset_password_sent_at 15 16 ## Rememberable 17 t.datetime :remember_created_at 18 19 ## Trackable 20 # t.integer :sign_in_count, default: 0, null: false 21 # t.datetime :current_sign_in_at 22 # t.datetime :last_sign_in_at 23 # t.string :current_sign_in_ip 24 # t.string :last_sign_in_ip 25 26 ## Confirmable 27 # t.string :confirmation_token 28 # t.datetime :confirmed_at 29 # t.datetime :confirmation_sent_at 30 # t.string :unconfirmed_email # Only if using reconfirmable 31 32 ## Lockable 33 # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 34 # t.string :unlock_token # Only if unlock strategy is :email or :both 35 # t.datetime :locked_at 36 37 38 t.timestamps null: false 39 end 40 41 add_index :users, :email, unique: true 42 add_index :users, :reset_password_token, unique: true 43 # add_index :users, :confirmation_token, unique: true 44 # add_index :users, :unlock_token, unique: true 45 end 46end 47
回答1件
あなたの回答
tips
プレビュー