# Error in loading CSV fixtures (Rails 1.2.1, Ruby 1.8.5)

**URL:** <https://www.ruby-forum.com/t/error-in-loading-csv-fixtures-rails-1-2-1-ruby-1-8-5/85224>\
**Category:** Rails\
**Created:** [February 11, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/error-in-loading-csv-fixtures-rails-1-2-1-ruby-1-8-5/85224 "2007-02-11T18:26:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jens](https://www.ruby-forum.com/u/jens)\
**Post date:** [February 11, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/error-in-loading-csv-fixtures-rails-1-2-1-ruby-1-8-5/85224/1 "2007-02-11T18:26:34Z")

</div>

Hello,

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  
downtime.)

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  
id,name,district,country\_id,longitude,latitude,importance,area,inhabitants  
1,Aachen,NRW,276,6088538,50775620,3,0,26000  
2,Achim bei Bremen,NDS,276,9025491,53012831,3,0,25000  
3,Ahaus,NRW,276,7003480,52079246,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  
rake aborted!  
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  
correct:

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  
end

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!

Jens
