2

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'
noisy
  • 6,495
  • 10
  • 50
  • 92

2 Answers2

7

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"
        }
    }
]
Community
  • 1
  • 1
ts_pati
  • 532
  • 1
  • 5
  • 9
  • 1
    Is there a way to do this in python so you can read in secrets from env variables? This doesn't seem like a very secure way to do this. – getup8 Apr 13 '16 at 23:00
2

Full fixture example, tested with django-allauth 0.19 and Django 1.8:

[
  {
    "model": "sites.site", 
    "pk": 1, 
    "fields": {
      "domain": "localhost", 
      "name": "localhost"
    }
  },
  {
        "model":"socialaccount.socialapp",
        "pk":1,
        "fields":{
            "id":"1",
            "provider":"facebook",
            "name":"facebook",
            "client_id":"0011223344556677",
            "secret":"012345678901234567890123456",
            "key":""
        }
  },
  {
        "model":"socialaccount.socialapp_sites",
        "pk":1,
        "fields":{
            "id":1,
            "socialapp_id":1,
            "site_id":1
        }
  }
]
ozren1983
  • 1,891
  • 1
  • 16
  • 34