質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

637閲覧

rails devis でmigrateできない

chibi0310mayu

総合スコア3

Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2021/04/27 04:01

前提・実現したいこと

ここに質問の内容を詳しく書いてください。
railsのdeviseでユーザー管理機能をしているのですが、maigrateができません。
ターミナルで以下のメッセージがでます

発生している問題・エラーメッセージ

rails aborted! ActiveRecord::NoDatabaseError: Unknown database 'photzoo_35_development' /Users/nakamatsumayumi/projects/photzoo-35/bin/rails:9:in `<top (required)>' /Users/nakamatsumayumi/projects/photzoo-35/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' Caused by: Mysql2::Error: Unknown database 'photzoo_35_development' /Users/nakamatsumayumi/projects/photzoo-35/bin/rails:9:in `<top (required)>' /Users/nakamatsumayumi/projects/photzoo-35/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) nakamatsumayumi@nakamatuminoMBP photzoo-35 %

該当のソースコード

マイグレーションファイル

class DeviseCreateUsers < ActiveRecord::Migration[6.0] def change create_table :users do |t| ## Database authenticatable t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" t.nickname :string, null: false t.family_name :string, null: false t.fist_name :string, null: false t.family_name_kana :string, null: false t.fist_name_kana :string, null: false t.birthdata :data, null: false ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at ## Rememberable t.datetime :remember_created_at ## Trackable # t.integer :sign_in_count, default: 0, null: false # t.datetime :current_sign_in_at # t.datetime :last_sign_in_at # t.string :current_sign_in_ip # t.string :last_sign_in_ip ## Confirmable # t.string :confirmation_token # t.datetime :confirmed_at # t.datetime :confirmation_sent_at # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at t.timestamps null: false end add_index :users, :email, unique: true add_index :users, :reset_password_token, unique: true # add_index :users, :confirmation_token, unique: true # add_index :users, :unlock_token, unique: true end end

database.yml

# MySQL. Versions 5.5.8 and up are supported. # # Install the MySQL driver # gem install mysql2 # # Ensure the MySQL gem is defined in your Gemfile # gem 'mysql2' # # And be sure to use new-style password hashing: # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html # default: &default adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: socket: /tmp/mysql.sock development: <<: *default database: photzoo_35_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: photzoo_35_test # As with config/credentials.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is # ever seen by anyone, they now have access to your database. # # Instead, provide the password as a unix environment variable when you boot # the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database # for a full rundown on how to provide these environment variables in a # production deployment. # # On Heroku and other platform providers, you may have a full connection URL # available as an environment variable. For example: # # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" # # You can use this database configuration with: # # production: # url: <%= ENV['DATABASE_URL'] %> # production: <<: *default database: photzoo_35_production username: photzoo_35 password: <%= ENV['PHOTZOO_35_DATABASE_PASSWORD'] %>

試したこと

マイグレーションファイルがおかしい?と思い見直しみましたがわからない
すいません。
何かアドバイスをおねがいします。

補足情報(FW/ツールのバージョンなど)

Ruby on rails 6
devise

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

マイグレーションファイルの記述が間違えてまして、なおしました。

t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" t.string :nickname , null: false t.string :family_name , null: false t.string :fist_name , null: false t.string :family_name_kana , null: false t.string :fist_name_kana , null: false t.date :birthdate , null: false

それでも同じエラーがでたので

rails db:migrate:reset

をしたら、なんとかできました。
sequelProでの確認は上の方の更新みたいなのをすると確認できた。

投稿2021/04/27 10:20

chibi0310mayu

総合スコア3

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問