【发布时间】:2016-07-28 04:24:06
【问题描述】:
您好,我一直在尝试将 Rails 应用程序部署到 Heroku,这是一个使用 Devise 的师生交流平台。该应用程序在本地运行良好,但我无法运行迁移,因此虽然主页等在 heroku 上运行良好,但当我点击注册时它不起作用(PG::UndefinedTable: ERROR....)
我已经对我的迁移文件进行了一些更改,以尝试更接近解决问题,现在它也不允许我在本地运行 rake db:migrate。
学生和教师是设计用户的类型。英语成绩和数学成绩属于一名教师和一名学生,教师/学生可以有许多这样的成绩。任务和生成的反馈属于老师。
rake db:migrate produces the following errors.
== 20160714153750 CreateGeneratedFeedbacks: migrating =========================
-- create_table(:generated_feedbacks)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "teachers" does not exist
: CREATE TABLE "generated_feedbacks" ("id" serial primary key, "performance_grade" character varying, "teacher_id" integer, "subject" character varying, "auto_feedback" text, "subcategory" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_ee351f38a1"
FOREIGN KEY ("teacher_id")
REFERENCES "teachers" ("id")
)
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `block in execute'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:566:in `block in log'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:560:in `log'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:in `execute'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:283:in `create_table'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:in `block in method_missing'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in `block in say_with_time'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in `say_with_time'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:in `method_missing'
/Users/Jack/programming/ruby/second_attempt/second_attempt/db/migrate/20160714153750_create_generated_feedbacks.rb:4:in `change'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:in `exec_migration'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:in `block (2 levels) in migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:in `block in migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:in `block in execute_migration_in_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in `block in ddl_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:in `transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in `ddl_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:in `execute_migration_in_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:in `block in migrate_without_lock'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in `each'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in `migrate_without_lock'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in `block in migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1298:in `with_advisory_lock'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:in `up'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:983:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/Users/Jack/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/Users/Jack/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "teachers" does not exist
: CREATE TABLE "generated_feedbacks" ("id" serial primary key, "performance_grade" character varying, "teacher_id" integer, "subject" character varying, "auto_feedback" text, "subcategory" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_ee351f38a1"
FOREIGN KEY ("teacher_id")
REFERENCES "teachers" ("id")
)
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `block in execute'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:566:in `block in log'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:560:in `log'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:in `execute'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:283:in `create_table'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:in `block in method_missing'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in `block in say_with_time'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in `say_with_time'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:in `method_missing'
/Users/Jack/programming/ruby/second_attempt/second_attempt/db/migrate/20160714153750_create_generated_feedbacks.rb:4:in `change'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:in `exec_migration'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:in `block (2 levels) in migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:in `block in migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:in `block in execute_migration_in_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in `block in ddl_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:in `transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in `ddl_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:in `execute_migration_in_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:in `block in migrate_without_lock'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in `each'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in `migrate_without_lock'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in `block in migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1298:in `with_advisory_lock'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:in `up'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:983:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/Users/Jack/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/Users/Jack/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
PG::UndefinedTable: ERROR: relation "teachers" does not exist
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `block in execute'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:566:in `block in log'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:560:in `log'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:in `execute'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:283:in `create_table'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:in `block in method_missing'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in `block in say_with_time'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in `say_with_time'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:in `method_missing'
/Users/Jack/programming/ruby/second_attempt/second_attempt/db/migrate/20160714153750_create_generated_feedbacks.rb:4:in `change'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:in `exec_migration'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:in `block (2 levels) in migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:in `block in migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:in `block in execute_migration_in_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in `block in ddl_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:in `transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in `ddl_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:in `execute_migration_in_transaction'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:in `block in migrate_without_lock'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in `each'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in `migrate_without_lock'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in `block in migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1298:in `with_advisory_lock'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:in `up'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:983:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:in `migrate'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/Users/Jack/.rvm/gems/ruby-2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/Users/Jack/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/Users/Jack/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
设计用户迁移
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: ""
#adding
t.string :type
t.string :teacher_name
t.string :teacher_email
## 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
#additional values
t.string :first_name
t.string :last_name
## 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
英语成绩(或多或少与数学相同)
class CreateEnglishGrades < ActiveRecord::Migration[5.0]
def change
create_table :english_grades do |t|
t.references :teacher, foreign_key: true
t.references :student, foreign_key: true
t.string :title
t.string :subcategory
t.string :performance_grade
t.string :feedback
t.date :grade_date
t.timestamps
end
end
end
生成的反馈: 类 CreateGeneratedFeedbacks
create_table :generated_feedbacks do |t|
t.string :performance_grade
t.references :teacher, foreign_key: true
t.string :subject
t.text :auto_feedback
t.string :subcategory
t.timestamps
end
end
end
任务:
class CreateTasks < ActiveRecord::Migration[5.0]
def change
create_table :tasks do |t|
t.string :subject
t.text :task
t.references :teacher, foreign_key: true
t.date :due_date
t.text :description
t.timestamps
end
end
end
型号
英语成绩(与数学成绩相同)
class EnglishGrade < ApplicationRecord
belongs_to :teacher
belongs_to :student
end
生成的反馈
class GeneratedFeedback < ApplicationRecord
belongs_to :teacher
end
用户
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
学生
class Student < User
has_many :grades
has_many :maths_grades
has_many :english_grades
has_many :generated_feedback
end
老师
class Teacher < User
has_many :grades
has_many :maths_grades
has_many :english_grades
has_many :generated_feedback
has_many :task
end
架构:
ActiveRecord::Schema.define(version: 20160713100728) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "english_grades", force: :cascade do |t|
t.integer "teacher_id"
t.integer "student_id"
t.string "title"
t.string "subcategory"
t.string "performance_grade"
t.string "feedback"
t.date "grade_date"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["student_id"], name: "index_english_grades_on_student_id", using: :btree
t.index ["teacher_id"], name: "index_english_grades_on_teacher_id", using: :btree
end
create_table "grades", force: :cascade do |t|
t.integer "student_id"
t.integer "teacher_id"
t.text "feedback"
t.integer "percentage_score"
t.string "grade_type"
t.string "grade_letter"
t.date "grade_date"
t.string "subject"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["student_id"], name: "index_grades_on_student_id", using: :btree
t.index ["teacher_id"], name: "index_grades_on_teacher_id", using: :btree
end
create_table "maths_grades", force: :cascade do |t|
t.integer "teacher_id"
t.integer "student_id"
t.string "title"
t.string "subcategory"
t.string "performance_grade"
t.string "feedback"
t.date "grade_date"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["student_id"], name: "index_maths_grades_on_student_id", using: :btree
t.index ["teacher_id"], name: "index_maths_grades_on_teacher_id", using: :btree
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
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"
t.string "first_name"
t.string "last_name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "type"
t.string "Teacher_name"
t.string "teacher_email"
t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end
end
非常感谢,我已经在这个问题上困扰了将近一周,因此我们将不胜感激。
可能相关或不相关的额外信息:
-我认为这可能是我的迁移文件的问题,因为我有一些后来添加了额外的列。为了尝试解决这个问题,我最近删除了这些额外的迁移文件并更新了现有迁移文件中我需要的列。
【问题讨论】:
-
您是否尝试过
rake db:reset或删除您的数据库并重新设置它(即rake db:drop db:create db:migrate),这样您至少可以让它再次在本地运行? -
尝试 rake db:reset....它将删除数据库并重新创建它并再次运行迁移......请注意,您将删除数据库....您的所有以前的数据将丢失
-
谢谢,我运行了 rake db:reset 然后 rake db:create 运行正常,但是当我运行 rake db:migrate 时,我得到:PG::UndefinedTable: ERROR: relationship "teachers" does not存在:CREATE TABLE“generated_feedbacks”(“id”序列主键,“performance_grade”字符变化,“teacher_id”整数,“主题”字符变化,“auto_feedback”文本,“子类别”字符变化,“created_at”时间戳不为空, “updated_at”时间戳不为空,约束“fk_rails_ee351f38a1”外键(“teacher_id”)引用“教师”(“id”))
-
rake db:reset什么都做......之后不要运行rake db:create和rake db:migrate......还可以尝试回到修改迁移之前的初始代码然后运行命令.....希望它会有所帮助 -
谢谢大家,问题最终与外键有关(由 Nic Nilov 提供),谢谢大家的帮助!
标签: ruby-on-rails devise