Opened 11 years ago
Last modified 11 years ago
#23415 closed Bug
OneToField reference to default 'id' instead of actual primary key — at Initial Version
| Reported by: | sky-chen | Owned by: | nobody |
|---|---|---|---|
| Component: | Migrations | Version: | 1.7 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Markus Holtermann | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Reproduce
- create a new project 'bug'
- create two app 'deg', 'pubsite'
- create models:
# bug/deg/models.py
from django.db import models
# Clients
class Client(models.Model):
client_id = models.IntegerField('ID', primary_key=True)
name = models.CharField('Name', max_length=255)
short_name = models.CharField('Short name', max_length=35)
class Meta:
managed = False
db_table = 'Clients'
verbose_name = 'Client'
# bug/pubsite/models.py
from django.db import models
from django.contrib.auth.models import User
from deg.models import Client
class Account(models.Model):
'''
Represents a general tranzsoft account,
which can be client of any associated departments
'''
user = models.OneToOneField(User)
deg_client = models.OneToOneField(Client)
- make migrations
- check sqlmigrate pubsite 0001
BEGIN; CREATE TABLE `pubsite_account` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `deg_client_id` integer NOT NULL UNIQUE, `user_id` integer NOT NULL UNIQUE); ALTER TABLE `pubsite_account` ADD CONSTRAINT pubsite_account_deg_client_id_1b7724045f4a7977_fk_Clients_id FOREIGN KEY (`deg_client_id`) REFERENCES `Clients` (`id`); ALTER TABLE `pubsite_account` ADD CONSTRAINT pubsite_account_user_id_3d5e7937e7fad36_fk_auth_user_id FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`); COMMIT;
Note:
See TracTickets
for help on using tickets.