Вопрос

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'
Это было полезно?

Решение

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"
        }
    }
]

Другие советы

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
        }
  }
]
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top