Foreword
Earlier I learned how to create a database table. The actual work is always. I often encounter the scene-to-table association scenario between tables. Today I will learn about one-to-one association.
models.py
Create a Card table in the models.py file and define the id, user, and add_time fields.
Create a CardInformation table, define the personal information in the table, and associate the two tables through OneToOneField
After creating the modles.py file, sync to the database.
python manage.py makemigrations
python manage.py migrate
After successful data migration, open the navicat client and view the database table.
Register xadmin background management
Register the Card table information in the project engineering adminx.py file
Note: inlines = [] Register the related table information to this table
Correlate CardInformation table information to Card table
Start the django service in the terminal:
python manage.py runserver 0.0.0.0:8000
Open the browser: ip: 8000 / xadmin /
Add bank card account information in the upper right corner, add account information to save
Open the navicat client to view the data, and the two tables normally add data.