#23415: OneToField reference to default 'id' instead of actual primary key
-------------------------------+--------------------
Reporter: sky-chen | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
== Reproduce ==
1. create a new project 'bug'
2. create two app 'deg', 'pubsite'
3. 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)
}}}
4. make migrations
5. 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;
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23415>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.f3746786e5a3661c31aa4f351a765f01%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.