jawosis
December 26, 2007, 5:36pm
1
I have:
class CreateGuests < ActiveRecord::Migration
def self.up
create_table :guests do |t|
t.string :namen
t.text :comment
t.integer :admin, :default => 0
t.integer :deleted, :default => 1
t.timestamps
end
Guest.create(:namen => "aaa, :comment => "bbb", :admin =>
1, :deleted => 0)
end
def self.down
drop_table :guests
end
end
Migration runs fine - “rake db:migrate --trace” gives no errors but
the guest is not created!
Any hints?
PS: I run Rails 2.0.2
Thanx
–
Jochen
jawosis
December 26, 2007, 5:45pm
2
Jochen K. wrote:
I have:
class CreateGuests < ActiveRecord::Migration
def self.up
create_table :guests do |t|
t.string :namen
t.text :comment
t.integer :admin, :default => 0
t.integer :deleted, :default => 1
t.timestamps
end
Guest.create(:namen => "aaa, :comment => "bbb", :admin =>
1, :deleted => 0)
You are missing a closing quote on the "aaa
jawosis
December 26, 2007, 5:50pm
3
Am 26.12.2007 um 17:45 schrieb Chris O.:
t.integer :deleted, :default => 1
t.timestamps
end
Guest.create(:namen => "aaa, :comment => "bbb", :admin =>
1, :deleted => 0)
You are missing a closing quote on the "aaa
Ups…I just replaced the real name with “aaa” and forgot the closing
quote.
jawosis
December 26, 2007, 5:57pm
4
Have you any validation rules that would prevent it being saved?
jawosis
December 26, 2007, 6:07pm
5
Jochen K. wrote:
Am 26.12.2007 um 17:45 schrieb Chris O.:
t.integer :deleted, :default => 1
t.timestamps
end
Guest.create(:namen => "aaa, :comment => "bbb", :admin =>
1, :deleted => 0)
You are missing a closing quote on the "aaa
Ups…I just replaced the real name with “aaa” and forgot the closing
quote.
Are you sure that this migration script is running, ie, are you fully
re-creating your db before each migration?
Are you able to enter the Guest.create(…) from the script/console?
jawosis
December 26, 2007, 6:02pm
6
Am 26.12.2007 um 17:56 schrieb John W.:
Have you any validation rules that would prevent it being saved?
I HAD some:
before_validation :trim_strings
before_save { |guest| guest.password = md5_pass(guest.password)
if guest.not_enabled? }
but I disabled them.
jawosis
December 26, 2007, 6:23pm
7
Am 26.12.2007 um 18:07 schrieb Chris O.:
You are missing a closing quote on the "aaa
Ups…I just replaced the real name with “aaa” and forgot the closing
quote.
Are you sure that this migration script is running,
rake db:migrate --trace
(in /Users/bullet/Documents/RAILS_WORK/…)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== 1 CreateSessions: migrating
– create_table(:sessions)
-> 0.0042s
– add_index(:sessions, :session_id)
-> 0.0408s
– add_index(:sessions, :updated_at)
-> 0.0112s
== 1 CreateSessions: migrated (0.0566s)
== 2 CreateGuests: migrating
– create_table(:guests)
-> 0.0124s
== 2 CreateGuests: migrated (0.1872s)
== 5 CreateLogins: migrating
– create_table(:logins)
-> 0.0046s
== 5 CreateLogins: migrated (0.0048s)
== 7 CreateGaleries: migrating
– create_table(:galeries)
-> 0.0099s
== 7 CreateGaleries: migrated (0.0101s)
== 8 CreatePics: migrating
– create_table(:pics)
-> 0.0071s
== 8 CreatePics: migrated (0.0073s)
== 9 CreateMessages: migrating
– create_table(:messages)
-> 0.0056s
== 9 CreateMessages: migrated (0.0059s)
== 10 CreateBookings: migrating
– create_table(:bookings)
-> 0.0166s
== 10 CreateBookings: migrated (0.0167s)
== 11 CreateAnswers: migrating
– create_table(:answers)
-> 0.0052s
== 11 CreateAnswers: migrated (0.0053s)
** Invoke db:schema:dump (first_time)
** Invoke environment
** Execute db:schema:dump
ie, are you fully re-creating your db before each migration?
In this special case here: Yes.
Are you able to enter the Guest.create(…) from the script/console?
g = Guest.new
=> #<Guest id: nil, salutation: nil, namen: nil, surname: nil, email:
nil, telephone: nil, mobile: nil, street: nil, city: nil, zip: nil,
password: nil, token: nil, company: nil, comment: nil, admin: 0,
deleted: 1, created_at: nil, updated_at: nil>
g.namen = “aaa”
=> “aaa”
g.save
=> false
Uuppps… I forgot one thing:
validates_confirmation_of :password, :message => “Passwörter stimmen
nicht überein!”, :on => :create
so I added
:password_confirmation => “bla bla…”
to my migration file!!
Thanx guys!
jawosis
December 27, 2007, 12:16am
8
Your admin and deleted fields should be booleans, not integers.
jawosis
December 26, 2007, 7:59pm
9
On Wed, 26 Dec 2007 17:35:46 +0100, Jochen K. wrote:
Guest.create(:namen => "aaa, :comment => "bbb", :admin =>
1, :deleted => 0)
I didn’t know you could put dummy data directly into the migration –
thanks!
-Thufir
jawosis
December 27, 2007, 12:20am
10
Am 27.12.2007 um 00:15 schrieb Ryan B.:
Your admin and deleted fields should be booleans, not integers.
This would not work here, because I need to store more then true or
false in this
two fields - I think I should find better labels for these
fields…perhaps rights and
status…
Thanx