ruby - DataMapper import primary key -


I am running an import script that uses the DataMaper to import the database's CSV dump into a local SQL database.

My models look like this:

  Class employees include DataMar :: Resources property: staff_id, string,: key => True Property: FullName, String and Class Project in Datamapar :: Resource Property: project_id, integer,: key = & gt; Real Property: Title, String Property: Position, String Related_to: Staff End  

The primary key is in the CSV, so when I import I am using it because this is the key The next time I run the import, I clean the tables and start again, although the datamaker provides because the primary key has already been taken.

Can the DataMapper be stopped or should I remove it? Create a blank.db file again before running the DB file and import? If so, what is the easiest way to do this.

You DataMapper.auto_migrate! to remove the table, and then they match the current model state. New tables will be empty of any data from previous runs.

So after defining your model, but before importing data, do something as follows:

  DataMapper.finalize.auto_migrate!  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -