当我尝试将数据转储到实时服务器上 Djanog 1.2.1 中的 JSON 固定装置时出现错误。在实时服务器上,它运行 MySQL 服务器版本 5.0.77,我使用 phpMyAdmin 界面将大量数据导入到我的表中。该网站运行良好,Django 管理员正常响应。但是,当我尝试实际转储与表对应的应用程序数据时,我收到此错误:
$ python manage.py dumpdata --indent=2 gigs > fixtures/gigs_100914.json
/usr/local/lib/python2.6/site-packages/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet
Error: Unable to serialize database: Location matching query does not exist.
我试图从中转储的“演出”的 Django 模型在 models.py 文件中如下所示:
from datetime import datetime
from django.db import models
class Location(models.Model):
name = models.CharField(max_length=120, blank=True, null=True)
class Meta:
ordering = ['name']
def __unicode__(self):
return "%s (%s)" % (self.name, self.pk)
class Venue(models.Model):
name = models.CharField(max_length=120, blank=True, null=True)
contact = models.CharField(max_length=250, blank=True, null=True)
url = models.URLField(max_length=60, verify_exists=False, blank=True, null=True) # because of single thread problems, I left this off (http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.URLField.verify_exists)
class Meta:
ordering = ['name']
def __unicode__(self):
return "%s (%s)" % (self.name, self.pk)
class Gig(models.Model):
date = models.DateField(blank=True, null=True)
details = models.CharField(max_length=250, blank=True, null=True)
location = models.ForeignKey(Location)
venue = models.ForeignKey(Venue)
class Meta:
get_latest_by = 'date'
ordering = ['-date']
def __unicode__(self):
return u"%s on %s at %s" % (self.location.name, self.date, self.venue.name)
就像我说的,Django 对数据很好。该网站运行良好,关系似乎运行得非常好。当运行命令以获取 SQL Django 正在使用的内容时:
$ python manage.py sql gigs
/usr/local/lib/python2.6/site-packages/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet
BEGIN;CREATE TABLE `gigs_location` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`name` varchar(120)
)
;
CREATE TABLE `gigs_venue` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`name` varchar(120),
`contact` varchar(250),
`url` varchar(60)
)
;
CREATE TABLE `gigs_gig` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`date` date,
`details` varchar(250),
`location_id` integer NOT NULL,
`venue_id` integer NOT NULL
)
;
ALTER TABLE `gigs_gig` ADD CONSTRAINT `venue_id_refs_id_3d901b6d` FOREIGN KEY (`venue_id`) REFERENCES `gigs_venue` (`id`);
ALTER TABLE `gigs_gig` ADD CONSTRAINT `location_id_refs_id_2f8d7a0` FOREIGN KEY (`location_id`) REFERENCES `gigs_location` (`id`);COMMIT;
我对数据进行了三次检查,确保所有关系和数据在导入后都正常。但是我仍然收到这个错误,三天后......我不知道该怎么做。我无法想象“弃用警告”在这里会成为问题。我真的需要将这些数据转储为 JSON。
非常感谢您的帮助。