I am redesigning a web application previously written in PHP. To do
development I need to fill a number of my models’ tables with static
data. I have written a conversion script (in Ruby) to extract the data
from the old database and convert it a bit.
For now, I wrote a script in db/fixtures/convert.rb which takes a
number of CSV files in db/fixtures/static/*csv containing the old
data, and produces converted tables in db/fixtures/$TABLE_NAME.csv.
(BTW: Is this the “right way” of doing this? In the end, I’d like to
write a rake task that calls my convert script to import all data from
the current PHP production DB, converts it, imports it into the Rails
app, and then I can switch production environments with minimal
Now I want to import these resulting CSV files with “rake
db:fixtures:load”. One table e.g. looks like this:
$ cat db/fixtures/cities.csv
2,Achim bei Bremen,NDS,276,9025491,53012831,3,0,25000
But when I try to import this data I get:
$ rake --trace db:fixtures:load
** Invoke db:fixtures:load (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:fixtures:load
SQLite3::SQLException: SQL logic error or missing database: INSERT
INTO cities (“id”) VALUES (2)
I don’t get this:
- Why is it trying to insert only the ID? I’m quite sure it fails
because my DB schema specifies “:null => false” for some of the other
colums, such as “name”, but why doesn’t it take the other columns too?
- Why is it not starting with inserting the first object (ID=1)?
- How do I get this working?
My development and test databases exist and the structures are
create_table “cities”, :force => true do |t|
t.column “name”, :string, :null => false
t.column “district”, :string
t.column “country_id”, :integer, :null => false
t.column “longitude”, :integer
t.column “latitude”, :integer
t.column “importance”, :integer
t.column “area”, :integer
t.column “inhabitants”, :integer
I read the load_fixtures.rb file from ActiveRecord (where the error is
triggered) but I don’t quite know how to debug this further, and I
don’t want to muck about in the AR code.
Any help would be appreciated!