AssertionError: ForeignKey cannot define a relation with abstract class Attribute

抽象クラスを外部キーに指定できない、どうしよう。

AssertionError: ForeignKey cannot define a relation with abstract class Attribute

 

抽象クラス(抽象モデル)に対して、CREATE する SQL 文がないことを確認する。

$ sudo python manage.py sql transmission
BEGIN;
...

 

神様に聞いてみた

So you've got three choices here:
1) Change Author to a standard model instead of abstract. Then you can create foreign keys to Author and pass in any subclass of Author your like.
2) Use generic foreign keys
3) Don't break up the models in the first place.

python - Make model reference abstract model in one-to-many - Stack Overflow

 

「Change Author to a standard model instead of abstract.」だって?調べてみる。
 

モデルの継承
1. 抽象ベースのモデルクラス
2. マルチテーブル継承
3. プロキシモデル
 

わいが取っていたのは①の方法。②の方法を取ると、抽象モデルと言うか、親モデルを問題なく外部キーに指定できた。
 

すごいなぁ、内部で ORDBMS みたいになってるんか。みんなMySQLのほうがシェア高いって聞くけど、継承とかのクラスにはどう対応してるのかなと思ったらこういうことだったのね。なんのために、Postgres 選んだんだろう(遠い目)MySQLに戻そうかな。