2014-01-05 102 views
0

我想将我的Django应用程序数据库从SQLite迁移到MySQl。DeserializationError:'NoneType'对象没有使用Django loaddata的属性'_meta'

我使用反倾销manage.py dumpdata --natural > hunt.json

然后更新设置时,我loaddata使用manage.py loaddata hunt连接到MySQL数据库,之后引发以下错误

Problem installing fixture 'hunt.json': Traceback (most recent call last): 
    File "C:\Python27\lib\site-packages\django\core\management\commands\loaddata.p 
y", line 190, in handle 
    for obj in objects: 
    File "C:\Python27\lib\site-packages\django\core\serializers\json.py", line 47, 
in Deserializer 
    raise DeserializationError(e) 
DeserializationError: 'NoneType' object has no attribute '_meta' 

下面的数据是我的模型。 py

from django.db import models 

class DJManager(models.Manager): 
    def get_by_natural_key(self, name): 
     return self.get(name=name) 

class DJ(models.Model): 
    objects = DJManager() 

    name = models.CharField(max_length=50, unique=True) 
    rank = models.IntegerField() 
    img = models.ImageField(upload_to='/img/', height_field=None, width_field=None) 
    soundcloud_profile = models.CharField(max_length=100, blank=True, null=True) 

    def natural_key(self): 
    return (self.name,) 

    #for human readable representation of objects 
    def __unicode__(self): 
     return self.name 

class Song(models.Model): 
    song_id = models.IntegerField() 
    name = models.CharField(max_length=100) 
    title = models.CharField(max_length=100) 
    normalized_name = models.CharField(max_length=100) 
    artist = models.ForeignKey(DJ, default=None, blank=True, null=True) 
    artists = models.CharField(max_length=100) 
    remixers = models.CharField(max_length=100, default=None, blank=True, null=True) 
    release_date = models.DateField() 
    slug = models.CharField(max_length=100) 
    artwork = models.CharField(max_length=100) 
    genres = models.CharField(max_length=50) 
    duplicate = models.BooleanField(default=False) 
    votes = models.IntegerField(default=0) 

    #for human readable representation of objects 
    def __unicode__(self): 
     return self.normalized_name 

回答

-1

南与试验冲突。我应该根据docs设置SOUTH_TESTS_MIGRATE = Falsesettings.py

If this is False, South’s test runner integration will make the test database be created using syncdb, rather than via migrations (the default).

此外,我正在倾倒所有东西进入我的夹具。这显然是与南方做固定装置的一种不好的方式 - 因为它也将南方的偏移表转移到夹具中。所以我不得不创建我的灯具是应用特定的 manage.py dumpdata hunt --natural > hunt.json

0

您需要在DJ模型中定义一个natural_key()方法

def natural_key(self): 
    return self.name 

你可以检查一下Django文档上:https://docs.djangoproject.com/en/dev/topics/serialization/#dependencies-during-serialization

+0

使用,给出了一个'DeserializationError:[U“‘硬威尔’值必须为整数”]' –

+0

好吧,我本来是要使用'回报率(自.name,)'因为它必须返回一个元组,但'NoneType'对象没有属性'_meta'错误依然存在。 –

相关问题