私は南にかなり新しいです。私は友人のプロジェクトに取り組んでおり、彼はすでにいくつかの移行を行っているようです。
モデルがあり、そのモデルに 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
誰かがここで何が起こっているのかを明らかにしてもらえますか?