Note that there are some explanatory texts on larger screens.

plurals
  1. POrake db:migrate running all migrations correctly
    primarykey
    data
    text
    <p>I'm fairly new to Ruby on Rails here.</p> <p>I have 2 migrate files that were provided. The first one, prefixed with 001, creates a table and some columns for that table. The next migrate file, prefixed with 002, inserts rows into the table created in file 001. </p> <p>Running the migration (rake db:migrate in command line) correctly creates the table but doesn't insert any of the data which is the problem. The code from the insertion looks like this (except with a lot more Student.create statements,</p> <pre><code>class AddStudentData &lt; ActiveRecord::Migration def self.up ... Student.create(:name =&gt; "Yhi, Manfredo", :gender =&gt; "M") ... end def self.down Student.delete_all end end </code></pre> <p>My understanding is that Student is a model object, so my Student model looks like this,</p> <pre><code>class Student &lt; ActiveRecord::Base end </code></pre> <p>Do I need to explicitly define a create method in Student or is that something that's given? (This project was made using scaffold)</p> <p>Thanks.</p> <p>Edit 1: I used Damien's suggestion and called <code>create!</code> instead of <code>create</code> but got the same response. Then what I did to see whether the code was even reaching that far was call this,</p> <pre><code>Student.create12312313!(:name =&gt; "foo", :gender =&gt; "M") </code></pre> <p>which is obviously invalid code and the migrate didn't throw any error. </p> <p>Edit2: Answer found. The schema_migrations table had its version set to 3, and I only had 3 different migration files so it never ran any of the migration files I had. That's why nothing was ever updating, and the bogus creates I used were never throwing errors. The reason the student data wasn't inserted the first time was because a certain table was already in the database and it caused a conflict the first time I migrated. So what I was really looking for wasn't <code>db:migrate</code> but rather <code>db:reset</code> Several hours well spent.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload