simonw / csvs-to-sqlite

Convert CSV files into a SQLite database
Apache License 2.0
878 stars 69 forks source link

multiple CSV files and foreign keys #61

Closed JBPressac closed 3 years ago

JBPressac commented 4 years ago

Hello, In the case when you want to import for instance: people.csv and coutry.csv where people.csv contains:

id, name, country_id 1, John, 1 2, Paul, 1 3, René, 2

and country.csv contains:

id, name 1, United Kingdom 2, France

Would it be possible to declare country_id as a foreign key of id in country.csv ? Thanks,

aguinane commented 3 years ago

Looks like you can achieve this with sqlite-utils:

sqlite-utils add-foreign-key database.db People country_id Country id
simonw commented 3 years ago

Yes, sqlite-utils is the right tool for this.