1
所以我看到有很多這類問題出現了(很少回答),而且在我看到的Django方面沒有。我很困惑,爲什麼我得到這個錯誤,我猜我缺少一些關於我的領域裝飾器的東西,或者是什麼不在我的模型定義中,這裏有兩個模型......(一個縮寫)。主鍵設置爲true,在一個表的外鍵給人蔘考,但在遷移我得到這個錯誤:django遷移錯誤:「沒有與給定鍵相匹配的唯一約束
django.db.utils.ProgrammingError: there is no unique constraint matching given keys for referenced table "swsite_zoneentity"
編輯了過時的代碼...
class ZoneEntity(models.Model):
zone_number = models.CharField(max_length=100, primary_key=True)
mpoly = models.PolygonField() #this should grow and shrink for the most representative one...
objects = models.GeoManager()
created_at=models.DateField(auto_now_add=True)
updated_at=models.DateField(auto_now=True)
class CesiumEntity(models.Model):
be_number = models.CharField(max_length=100) #the number assigned to a foot print to distinguish
#zone_id = models.CharField(max_length=100, null=True, blank=True)
zone_id = models.ForeignKey('ZoneEntity', null=True, blank=True)
好了沒有,你建議(更新後),並重新運行makemigrations和遷移...並得到了相同的錯誤:(''django.db.utils.ProgrammingError:沒有唯一的約束匹配給定的鍵爲參考表「swsite_zoneentity」 ' – Codejoy
請檢查我的結果..我只是刪除了幾何因爲我沒有geodjango here ..無論如何,你可以刪除你的分貝和/或刪除你的migrations文件夾??這可能會導致不匹配 – bobleujr
我不想烤吐司我的d atabase,我可以只刪除遷移文件夾嗎?我認爲還有更多的步驟,但我如何重置這個空白。 – Codejoy