-2

I'm building a web app on Django. The client insists that some column on some table should be the primary key, he doesn't want autoincrement one. But also he wants that column to be modifiable in application, pointing that Postgres can deal with it (ON UPDATE CASCADE clause). How can I lead him out of it, or maybe I should agree to that? He's stubborn.

Edit: I want to know at least whether doing things as he says is harmful, or what are some gotchas in this approach.

janek37
  • 572
  • 5
  • 16
  • 1
    Whats his justification? – uncaught_exceptions Sep 07 '11 at 19:13
  • 1
    Why is he hiring you if he wants to do the development? If he thinks he's leading the development, let him. If he's hired you because you know better, then tell him no firmly and just do the right thing – Malcolm Box Sep 07 '11 at 19:13
  • It's actually an academic project (Polish Academy of Sciences) and he knows something (I sometimes forget he's got major in computer science...) but his ideas for a database are weird. He wants db to be optimalized in context of manual writing of SQL queries and looking on the results in the SQL shell and he wants to execute "select * from foo natural join bar" and see meaningful columns instead of auto-generated keys. Actually I've already knocked some crazy db ideas out of his head before. – janek37 Sep 07 '11 at 19:23
  • There's nothing obscene about what he's wanting. There's no need for a surrogate key if there is a perfectly workable natural key already in the data. Database design existed before ORM. – Daniel Lyons Sep 08 '11 at 05:48
  • I just thought that a changeable column isn't a perfectly workable natural key, because of the cascade. – janek37 Sep 08 '11 at 07:09

1 Answers1

0

It can be done, from Django's docs regarding auto pk:

If you'd like to specify a custom primary key, just specify primary_key=True on one of your fields. If Django sees you've explicitly set Field.primary_key, it won't add the automatic id column.

However, pk's are usually used for object identity and retrieval. Managing them manually and ensuring uniqueness is a PITA, it's not just editing them, the also need to present and unique when the object is created and stored in the db for example.

mkriheli
  • 1,788
  • 10
  • 18