title: Migration/model issue PG::UndefinedTable: ERROR: relation "teachers" does not exist
body: <p>Hi I've been trying to deploy a rails app to Heroku which is a student-teacher communication platform using Devise. The app was running fine locally but I was unable to run the migration so although the home page etc. worked fine on heroku, when I clicked Sign up it didn't work (PG::UndefinedTable: ERROR....)</p>
  
  <p>I've made some changes to my migration files to try to get closer to solving the problem and now it doesn't let me run rake db:migrate locally either.</p>
  
  <p>Students and Teachers are types of Devise Users. English Grades and Maths Grades belong to one teacher and one student and teachers/students can have many of these grades. Tasks and generated feedbacks belong to a teacher.</p>
  
  <pre><code>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 &lt;top (required)&gt;'
  /Users/Jack/.rvm/gems/ruby-2.3.0/gems/rake-11.2.2/exe/rake:27:in `&lt;top (required)&gt;'
  /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 `&lt;main&gt;'
  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 &lt;top (required)&gt;'
  /Users/Jack/.rvm/gems/ruby-2.3.0/gems/rake-11.2.2/exe/rake:27:in `&lt;top (required)&gt;'
  /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 `&lt;main&gt;'
  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 &lt;top (required)&gt;'
  /Users/Jack/.rvm/gems/ruby-2.3.0/gems/rake-11.2.2/exe/rake:27:in `&lt;top (required)&gt;'
  /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 `&lt;main&gt;'
  Tasks: TOP =&gt; db:migrate
  </code></pre>
  
  <p>Devise user migration</p>
  
  <pre><code>class DeviseCreateUsers &lt; 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
  </code></pre>
  
  <p>English grades (more or less the same as maths)</p>
  
  <pre><code>class CreateEnglishGrades &lt; 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
  </code></pre>
  
  <p>Generated feedback:
      class CreateGeneratedFeedbacks &lt; ActiveRecord::Migration[5.0]
        def change</p>
  
  <pre><code>    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
  </code></pre>
  
  <p>Tasks:</p>
  
  <pre><code> class CreateTasks &lt; 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
  </code></pre>
  
  <p>Models</p>
  
  <p>English Grade (same as maths grade)</p>
  
  <pre><code>class EnglishGrade &lt; ApplicationRecord
    belongs_to :teacher
    belongs_to :student
  end
  </code></pre>
  
  <p>Generated Feedback</p>
  
  <pre><code>class GeneratedFeedback &lt; ApplicationRecord
    belongs_to :teacher
  end
  </code></pre>
  
  <p>User </p>
  
  <pre><code>class User &lt; ApplicationRecord
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable
  end
  </code></pre>
  
  <p>Student</p>
  
  <pre><code>class Student &lt; User
      has_many :grades
      has_many :maths_grades
      has_many :english_grades
      has_many :generated_feedback
  end
  </code></pre>
  
  <p>Teacher</p>
  
  <pre><code>class Teacher &lt; User
      has_many :grades
      has_many :maths_grades
      has_many :english_grades
      has_many :generated_feedback
      has_many :task
  end
  </code></pre>
  
  <p>Schema: </p>
  
  <pre><code>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
  </code></pre>
  
  <p>Thank you so much, I've been stuck on this issue for almost a week and so any help would be greatly appreciated. </p>
  
  <p>Extra information that may or may not be relevant:</p>
  
  <p>-I thought it may have been an issue with my migration files as I'd had some which added extra columns later on. To try to solve the problem I recently deleted these additional migration files and updated the columns I needed in the existing migration files. </p>