Search code examples
djangojsondjango-allauthdjango-fixtures

Django fixtures for model from imported application (like django-allauth)


I know that is possible to create fixtures file like initial_data.json for my own model. I want to create similar file for tables which are created and used by imported django-allauth application.

I tried:

[
    {
        "model":"allauth.socialaccount.models.SocialApp",
        "pk":1,
        "fields":{
            "id":"1",
            "provider":"facebook",
            "name":"facebook",
            "client_id":"0011223344556677",
            "key":"",
            "secret":"012345678901234567890123456"
        }
    }
]

However it's ends up with error:

python manage.py syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
DeserializationError: Problem installing fixture 'initial_data.json': 
  Invalid model identifier: 'allauth.socialaccount.models.SocialApp'

Solution

  • I found here that table from model django.contrib.sites.models.Site can be populate using

    [
      {
        "model": "sites.site", 
        "pk": 1, 
        "fields": {
          "domain": "myproject.mydomain.com", 
          "name": "My Project"
        }
      }
    ]
    

    So model allauth.socialaccount.models.SocialApp probably can by populated by:

    [
        {
            "model":"socialaccount.socialapp",
            "pk":1,
            "fields":{
                "id":"1",
                "provider":"facebook",
                "name":"facebook",
                "client_id":"0011223344556677",
                "key":"",
                "secret":"012345678901234567890123456"
            }
        }
    ]