我对南方很陌生。我正在处理一个朋友项目,他似乎已经完成了一些迁移。
我有一个模型,我正在尝试向它添加一个额外的 ManyToMany 字段。这是owned_geofences
我要添加的字段的类:
class UserProfile(models.Model):
owned_beacons = models.ManyToManyField(
Beacon,
blank=True,
null=True,
related_name='owned_beacons'
)
#trying to add this one below
owned_goefences = models.ManyToManyField(
Geofence,
blank=True,
null=True,
related_name='owned_geofences'
)
该应用程序名为“个人资料”。首先我这样做:
$ sudo python manage.py schemamigration profile --auto
+ Added M2M table for owned_goefences on profile.UserProfile
Created 0007_auto.py. You can now apply this migration with: ./manage.py migrate profile
酷,它似乎奏效了。然后我这样做了:
$ python manage.py migrate profile
Running migrations for profile:
- Migrating forwards to 0007_auto.
> profile:0007_auto
- Loading initial data for profile.
Installed 0 object(s) from 0 fixture(s)
好的。现在它应该工作正常吗?
嗯,它似乎确实奏效了。我进行了一些测试,然后..
>>> user = User.objects.get(pk=1)
<User: nick>
# just to test if user is working properly
>>> user.get_profile().owned_beacons
<django.db.models.fields.related.ManyRelatedManager object at 0x1104e7d50>
# this is the one that isn't working
>>> user.get_profile().owned_geofences
AttributeError: 'UserProfile' object has no attribute 'owned_geofences'
最重要的是,出于好奇,我跑了:
$ python manage.py syncdb
Syncing...
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
Synced:
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.sites
> django.contrib.messages
> django.contrib.staticfiles
> django.contrib.admin
> django.contrib.admindocs
> south
Not synced (use migrations):
- pp.apps.careers
- pp.apps.contact
- pp.apps.geofencemanager
- pp.apps.locationmanager
- pp.apps.messagemanager
- django_extensions
- pp.profile
- pp.apps.beaconmanager
(use ./manage.py migrate to migrate these)
为什么这些不同步?我以为我搞砸了,所以我接受了上面的建议并跑了:
$ python manage.py migrate
Running migrations for careers:
- Nothing to migrate.
#etc for all of them
有人可以解释一下这里发生了什么吗?