11

これは私のmodels.pyです:移行を実行しようとすると、「次のコンテンツタイプが古く、削除する必要があります。これはどういう意味ですか、どうすれば解決できますか?

class Notification(models.Model): 
    user = models.ForeignKey(User) 
    createdAt = models.DateTimeField(auto_now_add=True, blank=True) 
    read = models.BooleanField(default=False, blank=True) 

    class Meta: 
     abstract = True 

class RegularNotification(Notification): 
    message = models.CharField(max_length=150) 
    link = models.CharField(max_length=100) 

class FNotification(Notification): 
    # same as Notification 
    pass 

私はpython manage.py makemigrationsを行うと、これはそれが言うことである:

Migrations for 'CApp': 
    0019_auto_20151202_2228.py: 
    - Create model RegularNotification 
    - Create model FNotification 
    - Remove field user from notification 
    - Add field f_request to userextended 
    - Delete model Notification 

まずuserが私Notiicationモデルにまだあるので、それはそれはRemove field user from notificationを言うことを奇妙です(なぜ誰かが「通知からフィールドユーザを削除する」と言う理由を理解できればそれはすばらしいことです!)しかし、私が移動してやろうとするとpython manage.py migrate私はこのメッセージを受け取ります:

Applying CMApp.0019_auto_20151202_2228... OK 
The following content types are stale and need to be deleted: 

    CApp | notification 

Any objects related to these content types by a foreign key will also 
be deleted. Are you sure you want to delete these content types? 
If you're unsure, answer 'no'. 

    Type 'yes' to continue, or 'no' to cancel: no 

私はnoとタイプしました。しかし、正確にはどういう意味ですか、なぜ私はこのメッセージを受け取っていますか、私はこのメッセージを必要としないようにするにはどうすればいいですか?

+0

私はリポジトリの最後のコミットをプルするのを忘れてしまったので、これを得ました。私の最新のローカル移行は、リポジトリの最新のものではありませんでした。 :P私はリモートコードを引っ張って、私は再びマイグレーションを行い、私は魅力的に働いた。 – joaorodr84

答えて

10

モデルを削除/削除して移行を実行すると、メッセージが表示されます。

ほとんどの場合、安全に削除できます。ただし、場合によってはこれがデータ損失につながる可能性があります。他のモデルに削除されたモデルへの外部キーがある場合、これらのオブジェクトも削除されます。

Here's the django ticket that requests to make deleting stale content types safer.

@のX-ユーリが指摘したようにEDIT

は、このチケットは、固定されており、Django 1.11にリリースされました。

+0

ああ、 'Abstract = True'を' Notification'モデルに追加したので、おそらくDjangoはそれを削除したと仮定しています。なぜそれが「通知からフィールドユーザを削除する」と言うのか? 'user' ForeignKeyがまだそこにあるので、なぜDjangoはそれが削除されたと言っていますか? – user2719875

+0

私はそれについて完全には分かりません。たぶん移行ファイルを追加して、何が起きているのかを調べることができます。 –

+0

@RodXavier私の場合、私はモデルBを外部キーで削除したモデルAを持っています。つまり、モデルB、Cのデータは、外部キーモデルAに?ありがとう – Pietro

関連する問題