Hanny Hanny -4 years ago 110
Python Question

Running a .sql file after migrations in django

I have setup my migrations in django (very small project); but I have a .sql file that has a bunch of data I need in the database.

What is the best way (or is it even possible) to have this .sql file executed after/during running migrations?

The sql file just contains an insert of the data like so:

INSERT INTO `mileages_mileages` (`id`, `miles`, `start_location`, `end_location`) VALUES
(NULL,3, 'Location 1', 'Location 2'),

I just need to execute that .sql file after running the initial migrations of my models.

Is that possible?

Answer Source

You can execute raw SQL

operations = [ migrations.RunSQL('source dump.sql') ]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download