New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixtures (initial data for table) #274

avelino opened this Issue Feb 22, 2018 · 0 comments


2 participants

avelino commented Feb 22, 2018

It’s sometimes useful to pre-populate your database with hard-coded data when you’re first setting up an data base.

We can do this to migration barriers but it's not the best place.


  • dumpdata (generate fixture with the data that is in the current database)
  • loaddata (load fixture file)

What is fixture file?

Is JSON (future we can support other formats: YAML) file, example:

    "database": "database_name",
    "table": "person",
    "pk": 1,
    "fields": {
      "first_name": "John",
      "last_name": "Lennon"
    "database": "database_name",
    "table": "person",
    "pk": 2,
    "fields": {
      "first_name": "Paul",
      "last_name": "McCartney"

Example of use

prest dumpdata > fixture.json
prest loaddata fixture.json

Possible problems

  1. loaddata: PK (which is in the fixture) already exists? - We return a warning to the user, we can not take the decision in erasing or which wants action by the user (developer, sysadmin, dba, ...)
  2. dumpdata: file exist: The command writes on stdout

@avelino avelino added the feature label Mar 6, 2018

@felipeweb felipeweb added this to the 0.4 milestone Jun 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment