私はこことRoRで新しいです。私は5時間座って、私のプログラムに何が間違っているのか分からない。私は厳格なチュートリアルを続き、これが起こった:RoR:テーブルが存在しないエラー
ルビーバージョン:2.2.4 Railsのバージョン:5.0.0.1 工夫バージョン:4.2.0
C:\RailsInstaller\Ruby2.2.0\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails db:migrate
rails aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Table 'rubyandroid_development.users' doesn't exist: CREATE UNIQUE INDEX `index_users_on_authentication_token` ON `users` (`authentication_token`)
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/db/migrate/20160826225028_devise_create_users.rb:12:in `block in change'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/db/migrate/20160826225028_devise_create_users.rb:3:in `change'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails:4:in `require'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails:4:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'rubyandroid_development.users' doesn't exist: CREATE UNIQUE INDEX `index_users_on_authentication_token` ON `users` (`authentication_token`)
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/db/migrate/20160826225028_devise_create_users.rb:12:in `block in change'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/db/migrate/20160826225028_devise_create_users.rb:3:in `change'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails:4:in `require'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails:4:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Mysql2::Error: Table 'rubyandroid_development.users' doesn't exist
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/db/migrate/20160826225028_devise_create_users.rb:12:in `block in change'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/db/migrate/20160826225028_devise_create_users.rb:3:in `change'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails:4:in `require'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails:4:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
== 20160826225028 DeviseCreateUsers: migrating ================================
-- create_table(:users)
-- add_index(:users, :authentication_token, {:unique=>true})
Process finished with exit code 1
ここデシベル/移行/ devise_create_usersコードは次のとおりです。ここで
class DeviseCreateUsers < ActiveRecord::Migration[5.0]
def change
create_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
t.string :name, :null => false, :default => ""
#token hinzugefügt
t.string :authentication_token
add_index :users, :authentication_token, :unique => true
## 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
はデシベル/移行add_devise_to_users
class AddDeviseToUsers < ActiveRecord::Migration[5.0]
def self.up
change_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## 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
# Uncomment below if timestamps were not included in your original model.
# 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
def self.down
# By default, we don't want to make any assumption about how to roll back a migration when your
# model already existed. Please edit below which fields you would like to remove in this migration.
raise ActiveRecord::IrreversibleMigration
end
end
です210
UPDATE:私は行のコメントを忘れていました: add_index:users、:authentication_token、:unique => true。移行、次のエラーが発生します:私はすくいデシベル行うときしかし、今
Mysql2::Error: Duplicate column name 'email': ALTER TABLE `users` ADD `email` varchar(255) DEFAULT '' NOT NULL
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/db/migrate/20160827004755_add_devise_to_users.rb:5:in `block in up'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/db/migrate/20160827004755_add_devise_to_users.rb:3:in `up'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails:4:in `require'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails:4:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
ActiveRecord::StatementInvalid: Mysql2::Error: Duplicate column name 'email': ALTER TABLE `users` ADD `email` varchar(255) DEFAULT '' NOT NULL
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/db/migrate/20160827004755_add_devise_to_users.rb:5:in `block in up'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/db/migrate/20160827004755_add_devise_to_users.rb:3:in `up'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails:4:in `require'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails:4:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Mysql2::Error: Duplicate column name 'email'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/db/migrate/20160827004755_add_devise_to_users.rb:5:in `block in up'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/db/migrate/20160827004755_add_devise_to_users.rb:3:in `up'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails:4:in `require'
C:/Benutzer/Clemens/RubymineProjects/RubyAndroid/bin/rails:4:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
== 20160827004755 AddDeviseToUsers: migrating =================================
-- change_table(:users)
あなたはどのチュートリアルに従っていますか?あなたのエラーメッセージには、ユーザーテーブルを作成せず、存在しないテーブルの特定の列にインデックスを適用していないと言います。 –
ここに私が続いたチュートリアルがあります:http://lucatironi.net/tutorial/2012/10/15/ruby_rails_android_app_authentication_devise_tutorial_part_one/このチュートリアルでは、使用されなくなったauthentication_tokenを使用しています。だから私はこれのための宝石をインストールしました(gem 'devise-token_authenticatable') – Peter
RailsのバージョンとDevise gemのバージョンを教えてください。 –