# Help with migrations and create

**URL:** <https://www.ruby-forum.com/t/help-with-migrations-and-create/97184>\
**Category:** Rails\
**Created:** [July 5, 2006, 2:50pm UTC](https://www.ruby-forum.com/t/help-with-migrations-and-create/97184 "2006-07-05T14:50:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ea666f/32.png) [@jeffl](https://www.ruby-forum.com/u/jeffl)\
**Post date:** [July 5, 2006, 2:50pm UTC](https://www.ruby-forum.com/t/help-with-migrations-and-create/97184/1 "2006-07-05T14:50:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeffl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ea666f/32.png) [@jeffl](https://www.ruby-forum.com/u/jeffl)\
**Post date:** [July 5, 2006, 3:16pm UTC](https://www.ruby-forum.com/t/help-with-migrations-and-create/97184/2 "2006-07-05T15:16:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeffl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ea666f/32.png) [@jeffl](https://www.ruby-forum.com/u/jeffl)\
**Post date:** [July 5, 2006, 3:30pm UTC](https://www.ruby-forum.com/t/help-with-migrations-and-create/97184/3 "2006-07-05T15:30:42Z")

</div>

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 =\> “removed\_email\_address@domain.invalid”, :internal\_team\_member =\> true,  
:admin =\> true,  
:password =\> “password”, :password\_confirmation =\>  
“password”)

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

```

:email =\> “removed\_email\_address@domain.invalid”, :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 =  
‘removed\_email\_address@domain.invalid’) 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

---

<div class="post-metadata">

**Author:** ![jeffl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ea666f/32.png) [@jeffl](https://www.ruby-forum.com/u/jeffl)\
**Post date:** [July 5, 2006, 4:43pm UTC](https://www.ruby-forum.com/t/help-with-migrations-and-create/97184/4 "2006-07-05T16:43:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jeffl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ea666f/32.png) [@jeffl](https://www.ruby-forum.com/u/jeffl)\
**Post date:** [July 6, 2006, 5:37am UTC](https://www.ruby-forum.com/t/help-with-migrations-and-create/97184/5 "2006-07-06T05:37:20Z")

</div>

Glad I could help 🙂

---

<div class="post-metadata">

**Author:** ![jeffl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ea666f/32.png) [@jeffl](https://www.ruby-forum.com/u/jeffl)\
**Post date:** [July 5, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/help-with-migrations-and-create/97184/6 "2006-07-05T17:02:45Z")

</div>

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!
