I just switched from MySQL to SQLite on a project and I decided to utilize migrations rather that just hacking the scema script to work with the new database. (to get SQlite support for migrations I am using the #1771 patch against 0.13.1) I have the table creation stuff done and working and am now trying to populat some initial data and have hit a snag. Here is an example: # states lookup table create_table :states do |t| t.column :created_at, :datetime t.column :updated_at, :datetime t.column :is_active, :boolean, :default => 1 t.column :name, :string t.column :postal_code, :string t.column :is_usa, :boolean, :default => 1 t.column :is_overseas, :boolean, :default => 0 end State.create :postal_code => ''NC'', :name => ''North Carolina'' It looks okay to me based on the API docs but I get rake aborted! uninitialized constant InitialSchema::State when I run ''rake migrate'' ... What have I missed? Thanks, Tim
Hello Tim, Tim said the following on 2005-09-19 15:55:> It looks okay to me based on the API docs but I get > > rake aborted! > uninitialized constant InitialSchema::State > > when I run ''rake migrate'' ... What have I missed?I hit the same thing. Simply require ''state'' and you should be fine. It looks like the migrations don''t automatically load dependencies. Bye ! François
Thanks ... that did the trick. One more problem, though. It seems that the ''id'' fileds are not being created automatically... How would I go about including them in the migration and specifying that they are primary keys? #tim Rails ML wrote:> Hello Tim, > > Tim said the following on 2005-09-19 15:55: > >> It looks okay to me based on the API docs but I get >> >> rake aborted! >> uninitialized constant InitialSchema::State >> >> when I run ''rake migrate'' ... What have I missed? > > > I hit the same thing. Simply require ''state'' and you should be fine. It > looks like the migrations don''t automatically load dependencies. > > Bye ! > François > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Hello Tim, Tim said the following on 2005-09-21 10:11:> Thanks ... that did the trick. One more problem, though. It seems that > the ''id'' fileds are not being created automatically... How would I go > about including them in the migration and specifying that they are > primary keys?If you use the block form of create_table, it automatically adds the primary key field. You have to give create_table an option to say you don''t want the primary key field. Use this: create_table :suppliers do |t| # ID field already in the table definition right here # Depending on the actual implementation of AbstractAdapter, # your field is a sequence, auto_increment integer, etc. t.column :name, :string, :limit => 60 # More fields here end Alternatively: create_table :categories_suppliers, :id => false do |t| # No ID field created t.column :supplier_id, :integer t.column :category_id, :integer end Hope that helps ! François
Well, that is what I *expected* but it just did not seem to happen :-) Here is a sample definition: create_table(:states) { |t| t.column :created_at, :datetime t.column :updated_at, :datetime t.column :is_active, :boolean, :default => 1 t.column :postal_code, :string t.column :name, :string t.column :is_usa, :boolean, :default => 1 t.column :is_overseas, :boolean, :default => 0 } This executes fine but I end up with a table that has no ''id'' column... I tried these variations to no avail: create_table(:states, :primary_key => ''id'') { |t| t.column :created_at, :datetime t.column :updated_at, :datetime t.column :is_active, :boolean, :default => 1 t.column :postal_code, :string t.column :name, :string t.column :is_usa, :boolean, :default => 1 t.column :is_overseas, :boolean, :default => 0 } create_table(:states) { |t| t.column :id, :integer t.column :created_at, :datetime t.column :updated_at, :datetime t.column :is_active, :boolean, :default => 1 t.column :postal_code, :string t.column :name, :string t.column :is_usa, :boolean, :default => 1 t.column :is_overseas, :boolean, :default => 0 } create_table(:states) { |t| t.column :id, :primary_key t.column :created_at, :datetime t.column :updated_at, :datetime t.column :is_active, :boolean, :default => 1 t.column :postal_code, :string t.column :name, :string t.column :is_usa, :boolean, :default => 1 t.column :is_overseas, :boolean, :default => 0 } Any other ideas? #tim François Beausoleil wrote:> Hello Tim, > > Tim said the following on 2005-09-21 10:11: > >> Thanks ... that did the trick. One more problem, though. It seems that >> the ''id'' fileds are not being created automatically... How would I go >> about including them in the migration and specifying that they are >> primary keys? > > > If you use the block form of create_table, it automatically adds the > primary key field. You have to give create_table an option to say you > don''t want the primary key field. > > Use this: > create_table :suppliers do |t| > # ID field already in the table definition right here > # Depending on the actual implementation of AbstractAdapter, > # your field is a sequence, auto_increment integer, etc. > > t.column :name, :string, :limit => 60 > # More fields here > end > > Alternatively: > create_table :categories_suppliers, :id => false do |t| > # No ID field created > t.column :supplier_id, :integer > t.column :category_id, :integer > end > > Hope that helps ! > François > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Never mind ... It seems the #1771 patch (SQLite migrations support) introduced a bug that prevented primary keys from being automatically created. The #1833 patch fixes it... cheers, #tim Tim wrote:> Well, that is what I *expected* but it just did not seem to happen :-) > > Here is a sample definition: > > create_table(:states) { |t| > t.column :created_at, :datetime > t.column :updated_at, :datetime > t.column :is_active, :boolean, :default => 1 > t.column :postal_code, :string > t.column :name, :string > t.column :is_usa, :boolean, :default => 1 > t.column :is_overseas, :boolean, :default => 0 > } > > This executes fine but I end up with a table that has no ''id'' column... > I tried these variations to no avail: > > create_table(:states, :primary_key => ''id'') { |t| > t.column :created_at, :datetime > t.column :updated_at, :datetime > t.column :is_active, :boolean, :default => 1 > t.column :postal_code, :string > t.column :name, :string > t.column :is_usa, :boolean, :default => 1 > t.column :is_overseas, :boolean, :default => 0 > } > > create_table(:states) { |t| > t.column :id, :integer > t.column :created_at, :datetime > t.column :updated_at, :datetime > t.column :is_active, :boolean, :default => 1 > t.column :postal_code, :string > t.column :name, :string > t.column :is_usa, :boolean, :default => 1 > t.column :is_overseas, :boolean, :default => 0 > } > > > create_table(:states) { |t| > t.column :id, :primary_key > t.column :created_at, :datetime > t.column :updated_at, :datetime > t.column :is_active, :boolean, :default => 1 > t.column :postal_code, :string > t.column :name, :string > t.column :is_usa, :boolean, :default => 1 > t.column :is_overseas, :boolean, :default => 0 > } > > > Any other ideas? > > #tim > > > François Beausoleil wrote: > >> Hello Tim, >> >> Tim said the following on 2005-09-21 10:11: >> >>> Thanks ... that did the trick. One more problem, though. It seems >>> that the ''id'' fileds are not being created automatically... How would >>> I go about including them in the migration and specifying that they >>> are primary keys? >> >> >> >> If you use the block form of create_table, it automatically adds the >> primary key field. You have to give create_table an option to say you >> don''t want the primary key field. >> >> Use this: >> create_table :suppliers do |t| >> # ID field already in the table definition right here >> # Depending on the actual implementation of AbstractAdapter, >> # your field is a sequence, auto_increment integer, etc. >> >> t.column :name, :string, :limit => 60 >> # More fields here >> end >> >> Alternatively: >> create_table :categories_suppliers, :id => false do |t| >> # No ID field created >> t.column :supplier_id, :integer >> t.column :category_id, :integer >> end >> >> Hope that helps ! >> François >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails