Comments (2)
Thanks for the feedback.
On Tue, Apr 23, 2013 at 10:51 PM, menelike [email protected] wrote:
Hello,
currently an update on the parent table doesn't update the children e.g.
in mysql it results in "Cannot delete or update a parent row". Deletes work
(warning in the admin menu doesn't include the children). Setting ON UPDATE
CASCADE on the foreign key in mysql does the job, but breaks the concept of
django with emulating the cascades.Besides: Great work simone, you've got the only working compound PK
solution working.from compositekey import db
from django.db import modelsclass Blog(models.Model):
id = db.MultiFieldPK("title", "author")
title = models.CharField(max_length=100)
author = models.CharField(max_length=100)class Meta: app_label = 'foo'
class Post(models.Model):
post = models.CharField(max_length=100)
blog = models.ForeignKey(Blog, to_field="id",
fields_ext={
"author": {"db_column" :"author"},
"title" : {"db_column" :"title"},
})
class Meta:
app_label = 'foo'CREATE TABLE IF NOT EXISTS
solar_post
(
id
int(11) NOT NULL AUTO_INCREMENT,
title
varchar(100) NOT NULL,
author
varchar(100) NOT NULL,
post
varchar(100) NOT NULL,
PRIMARY KEY (id
),
UNIQUE KEYbar
(title
,author
),
KEYsolar_post_841a7e28
(title
),
KEYsolar_post_a5d5a658
(author
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;#OLD:
#ALTER TABLEsolar_post
ADD CONSTRAINT
solar_post_ihgdbfk_1
FOREIGN KEY (title
,author
) REFERENCESsolar_blog
(title
,author
)#NEW
ALTER TABLEsolar_post
ADD CONSTRAINTsolar_post_ihgdbfk_1
FOREIGN KEY (title
,author
) REFERENCESsolar_blog
(title
,author
) ON UPDATE CASCADE—
Reply to this email directly or view it on GitHubhttps://github.com//issues/20
.
from django-compositekey.
Hi Simone,
the reason I deleted the issue is that it isn't actually an issue. Django primary keys should be immutable, even on normal foreign key relations there is no ON UPDATE CASCADE feature in django itself. This results in that primary compund keys should be immutable too. In my case the primary keys are mutable, the CASCADE ON UPDATE is a database driven solution, but it's always the best solution to stay with immutable primary key(s) anyway.
Keep up the good work!
Regards
from django-compositekey.
Related Issues (20)
- Some Pending Constraint for the new API fails
- Composite primary key generation/display of m2m join tables HOT 3
- DoesNotExist error raised when instantiating composite key model with no parameters HOT 2
- Django v1.5 - ImportError: cannot import name LHS_JOIN_COL HOT 3
- get related foreign key targets name and not attname HOT 1
- Naive assumption of "quote" function and "||" operator existence and behavour? HOT 3
- please can you put in https://pypi.python.org/pypi/django-compositekey the last version of branch 1.4.x ?? HOT 1
- package install off PyPI drops AUTHORS in current directory
- Django 1.6 and upcoming 1.7 compat HOT 16
- Support python3
- select_related and no field.rel.to HOT 1
- Legacy read-only DB with no primary key HOT 5
- ValueError: need more than 5 values to unpack HOT 1
- Attempt to append to unique_together tuple HOT 6
- quantize result has too many digits for current context HOT 1
- Django 1.4 enabling compositekey breaks unrelated models HOT 1
- ImportError: cannot import name EmptyShortCircuit HOT 2
- C HOT 1
- Urgent Help: Trying to implement composite Primary Key - Got Below Error HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-compositekey.