4

プレイリストという名前の列が存在しないというDatabaseErrorが発生し、それを修正する方法を見つけようとしています。私は南を使用しています。移行フォルダー内の古いファイルを削除して、次のコマンドを実行しました。

python manage.py schemamigration app_name --initial
python manage.py migrate reserve

これを行うと、このエラーが発生します。

south.exceptions.GhostMigrations: 

 ! These migrations are in the database but not on disk:
    <reserve: 0002_initial>
 ! I'm not trusting myself; either fix this yourself by fiddling
 ! with the south_migrationhistory table, or pass --delete-ghost-migrations
 ! to South to have it delete ALL of these records (this may not be good). 

移行フォルダーにはinit.py(c)と0001_initial.py(c)しかないため、このエラーを取り除く方法がわかりません。0002移行ファイルはもうありません。

runserverを試し、管理者で[プレイリストの追加]をクリックすると、DatabaseErrorが発生します。それが役立つ場合、私のmodels.pyは次のとおりです。

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    def __unicode__(self):
        return self.user

def create_user_profile(sender, instance, created, **kwargs):
    if created:
        UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)         

class Playlist(models.Model):
    playlist = models.CharField('Playlist', max_length = 2000, null=True, blank=True)
    def __unicode__(self):
        return self.playlist

class Video(models.Model):
    video_url = models.URLField('Link to video', max_length = 200, null=True, blank=True)
    def __unicode__(self):
        return self.video_url

class UserPlaylist(models.Model):
    profile = models.ForeignKey(User)
    playlist = models.ForeignKey(Playlist)
    def __unicode__(self):
        return self.playlist

class Videoplaylist(models.Model):
    video = models.ForeignKey(Video)
    playlist = models.ForeignKey(UserPlaylist)
    def __unicode__(self):
        return self.playlist

これを修正する方法について何かアドバイスはありますか?

4

5 に答える 5

12

とにかく走れ

python manage.py migrate reserve --delete-ghost-migrations

これにより、存在しない移行がデータベース テーブルから削除されますsouth_migrationhistory

于 2012-10-26T15:34:48.840 に答える
3

最初に、データベースとファイルシステムの同期が取れなくなった原因を突き止める必要があります。

次に、適切な場合は、次のことができます

python manage.py migrate reserve --ignore-ghost-migrations

また

python manage.py migrate reserve --delete-ghost-migrations

Aidas が言ったように、より適切と思われる方を選択します。このignoreオプションはおそらくリスクが少ないですが、この状態になるには何かが間違っています.

于 2013-11-19T22:58:28.487 に答える
1

Southは、移行情報をデータベースの「移行」と呼ばれるテーブルにも保存します。[それがテーブル名だと思います。これをメモリから書き込む]。

そのテーブルをクリアする必要があります。

ノート

  • そのテーブルをクリアしたら、移行を最初からやり直す必要があります。最初の移行からすぐに。
  • これを行う前に、データベースのコピーをそのまま作成することをお勧めします。あなたのコードはすでにバージョン管理されていると思います。
于 2012-10-26T15:15:46.073 に答える