Created
November 26, 2018 12:13
-
-
Save kkirsanov/6e8fa5ff878397456dc1316aaaca5664 to your computer and use it in GitHub Desktop.
Как доавить UUID PK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Generated by Django 1.11 on 2017-05-31 11:05 | |
from __future__ import unicode_literals | |
from django.db import migrations | |
def load_stores_from_fixture(apps, schema_editor): | |
from django.core.management import call_command | |
call_command("loaddata", "dump.json") | |
def load_fixture(apps, schema_editor): | |
from django.core.serializers import base, python | |
from django.core.management import call_command | |
# Save the old _get_model() function | |
old_get_model = python._get_model | |
# Define new _get_model() function here, which utilizes the apps argument to | |
# get the historical version of a model. This piece of code is directly stolen | |
# from django.core.serializers.python._get_model, unchanged. | |
def _get_model(model_identifier): | |
try: | |
return apps.get_model(model_identifier) | |
except (LookupError, TypeError): | |
raise base.DeserializationError("Invalid model identifier: '%s'" % model_identifier) | |
# Replace the _get_model() function on the module, so loaddata can utilize it. | |
python._get_model = _get_model | |
# Call loaddata command | |
call_command('loaddata', 'dump.json', app_label='pay') | |
# Restore old _get_model() function | |
python._get_model = old_get_model | |
class Migration(migrations.Migration): | |
dependencies = [ | |
('sms', '0003_sms_uuid'), | |
('sessions', '0001_initial'), | |
] | |
operations = [ | |
migrations.RunPython(load_fixture), | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment