既存のデータベースをイントロスペクトしてモデルを作成するためにinspectdb
ツールを使用しました。Djangoの多対多関係「ProgrammingError:column shoe_size_run.idが存在しません」
部分ERD:
class Shoe(models.Model):
sku = models.AutoField(primary_key=True)
style_number = models.CharField(unique=True, max_length=6)
factory_style_number = models.CharField(unique=True, max_length=10, blank=True, null=True)
stock_name = models.CharField(max_length=10)
season = models.CharField(max_length=30)
date_created = models.DateField()
category_code = models.ForeignKey(Category, models.DO_NOTHING, db_column='category_code')
brand_code = models.ForeignKey(Brand, models.DO_NOTHING, db_column='brand_code')
factory_number = models.ForeignKey(Factory, models.DO_NOTHING, db_column='factory_number')
spec_sheet = models.ForeignKey('SpecSheet', models.DO_NOTHING, blank=True, null=True)
class Meta:
managed = False
db_table = 'shoe'
class ShoeSizeRun(models.Model):
sku = models.ForeignKey(Shoe, models.DO_NOTHING, db_column='sku')
size_run = models.ForeignKey('SizeRun', models.DO_NOTHING)
class Meta:
managed = False
db_table = 'shoe_size_run'
unique_together = (('sku', 'size_run'),)
class SizeRun(models.Model):
size_run_id = models.AutoField(primary_key=True)
run = models.IntegerField()
width = models.CharField(max_length=4)
pairs_of_five = models.IntegerField(blank=True, null=True)
pairs_of_five_and_half = models.IntegerField(blank=True, null=True)
pairs_of_six = models.IntegerField(blank=True, null=True)
pairs_of_six_and_half = models.IntegerField(blank=True, null=True)
pairs_of_seven = models.IntegerField(blank=True, null=True)
pairs_of_seven_and_half = models.IntegerField(blank=True, null=True)
pairs_of_eight = models.IntegerField(blank=True, null=True)
pairs_of_eight_and_half = models.IntegerField(blank=True, null=True)
pairs_of_nine = models.IntegerField(blank=True, null=True)
pairs_of_nine_and_half = models.IntegerField(blank=True, null=True)
pairs_of_ten = models.IntegerField(blank=True, null=True)
pairs_of_ten_and_half = models.IntegerField(blank=True, null=True)
pairs_of_eleven = models.IntegerField(blank=True, null=True)
pairs_of_eleven_and_half = models.IntegerField(blank=True, null=True)
pairs_of_twelve = models.IntegerField(blank=True, null=True)
class Meta:
managed = False
db_table = 'size_run'`
が、これらは、それらのテーブルのSQL定義している:
今CREATE TABLE shoe (
sku SERIAL NOT NULL,
style_number varchar(6) NOT NULL UNIQUE,
factory_style_number varchar(10) UNIQUE,
stock_name varchar(10) NOT NULL,
season varchar(30) NOT NULL,
date_created date NOT NULL,
category_code int4 NOT NULL,
brand_code int4 NOT NULL,
factory_number int4 NOT NULL,
spec_sheet_id int4,
PRIMARY KEY (sku));
CREATE TABLE shoe_size_run (
sku int4 NOT NULL,
size_run_id int4 NOT NULL,
PRIMARY KEY (sku,
size_run_id));
CREATE TABLE size_run (
size_run_id SERIAL NOT NULL,
run int4 NOT NULL,
width varchar(4) NOT NULL,
pairs_of_five int4,
pairs_of_five_and_half int4,
pairs_of_six int4,
pairs_of_six_and_half int4,
pairs_of_seven int4,
pairs_of_seven_and_half int4,
pairs_of_eight int4,
pairs_of_eight_and_half int4,
pairs_of_nine int4,
pairs_of_nine_and_half int4,
pairs_of_ten int4,
pairs_of_ten_and_half int4,
pairs_of_eleven int4,
pairs_of_eleven_and_half int4,
pairs_of_twelve int4,
PRIMARY KEY (size_run_id));
ALTER TABLE shoe_size_run ADD CONSTRAINT FKshoe_size_544815 FOREIGN KEY (sku) REFERENCES shoe (sku);
ALTER TABLE shoe_size_run ADD CONSTRAINT FKshoe_size_544404 FOREIGN KEY (size_run_id) REFERENCES size_run (size_run_id);
、私は多対を使用して問題を持っていますDjangoの多対多テーブルなぜこのエラー?
どうすればこの問題を解決できますか?
スタックトレースのテキストコンテンツ(「コピー&ペースト表示に切り替える」)をコピーして、スクリーンショットをそれに置き換えてください。また、エラーが発生したときに呼び出されているビューコードを投稿します。 – solarissmoke
@solarissmoke私はちょうどそれを追加しました、ありがとう。 – Fabio