我对 Django 和 Postres 有疑问。
Python 3.5 Django 2.2.7 psycopg2 2.8.4 postgres 9.5.19
楷模:
class Model1(models.Model):
model1_name = models.CharField(max_length=20)
class Model2(models.Model):
model2_name = models.CharField(max_length=20)
model_keys = models.ManyToManyField(Model1, blank=True)
Run Code Online (Sandbox Code Playgroud)
Postgress 数据库为空:
my_base=> \d
No relations found.
Run Code Online (Sandbox Code Playgroud)
我做迁移...
python3 manage.py makemigrations
project/migrations/0004_model1_model2.py
- Create model Model1
- Create model Model2
python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, engine_st, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying …Run Code Online (Sandbox Code Playgroud)