Help with migrations and create

After creating a table in a create table migration, I’m then attempting
to populate a couple of rows of data in the table using the create
method. The first row gets inserted into the database, but any further
calls generate a select against the database, but no insert.

Am I doing something wrong, or is it inappropriate to create more than a
single row of data in a table using migrations? What is the correct way
to populate application necessary data (not test data - actual data, in
this case some prompt value for validation) into any environment?

Thanks much!
Jef

Jeff LaMarche wrote:

After creating a table in a create table migration, I’m then attempting
to populate a couple of rows of data in the table using the create
method. The first row gets inserted into the database, but any further
calls generate a select against the database, but no insert.

Am I doing something wrong, or is it inappropriate to create more than a
single row of data in a table using migrations? What is the correct way
to populate application necessary data (not test data - actual data, in
this case some prompt value for validation) into any environment?

Thanks much!
Jef

Could you post the text of your migration? or at least the portion for
the table in question.

Thanks, in advance,

-Sean

sean lynch wrote:

Could you post the text of your migration? or at least the portion for
the table in question.

Sure. I’ve had to remove and edit some data in the create statements for
reasons of privacy:

class CreatePeople < ActiveRecord::Migration
def self.up
create_table :people do |t|
t.column :name, :string, :null => false
t.column :short_name, :string
t.column :email, :string
t.column :internal_team_member, :boolean, :default => false
t.column :admin, :boolean, :default => false

  # Authentication - for internal team members only
  t.column :hashed_password,    :string
  t.column :salt,               :string

  t.column :created_at, :timestamp
  t.column :modified_at, :timestamp
end

add_index :people, :name
add_index :people, :short_name



Person.create(:name => "Jeff LaMarche", :short_name => "Jeff", 

:email => “[email protected]”, :internal_team_member => true,
:admin => true,
:password => “password”, :password_confirmation =>
“password”)

Person.create(:name => "Another Person", :short_name => "Becka", 

:email => “[email protected]”, :internal_team_member => true,
:admin => false, :password => “password”,
:password_confirmation => “password”)

end

def self.down
drop_table :people
end
end

What happens is that the user “Jeff LaMarche” gets created, but the
second user does not. What does happen, if I trace the SQL is:

Person Load (0.000491) SELECT * FROM people WHERE (people.name =
‘Another Person’) LIMIT 1
Person Load (0.000427) SELECT * FROM people WHERE (people.short_name
= ‘Becka’) LIMIT 1
Person Load (0.000586) SELECT * FROM people WHERE (people.email =
[email protected]’) LIMIT 1

No insert happens, just the three selects above.

For the record, I’m on Mac OS X 10.4.7 running PostgreSQL 8.1.4 and
Rails 1.1.2

Thanks much in advance!
Jeff

Could be a validation isn’t passing. Do you have any yet?

Write a quick unit test for your Person that attempts to create that
user,
or attempt to create that use via script/console and see if it saves the
record, or if there are errors.

Glad I could help :slight_smile:

Brian H. wrote:

Could be a validation isn’t passing. Do you have any yet?

Well, duh. Now I feel stupid. Yeah, that’s it. I was doing a
validates_presence_of on a :boolean with a default value of false.

I love Ruby, but the boolean behavior still trips me up sometimes.
Thanks for the help!