Django: Ticket #15238: global TABLE_PREFIX settinghttps://code.djangoproject.com/ticket/15238
<p>
Followed by <a class="ext-link" href="http://groups.google.com/group/django-developers/browse_thread/thread/d28d38e9ae14e6a5"><span class="icon">​</span>this discussion</a>. There should be TABLE_PREFIX property, which will be prepended to all generated db_table options
</p>
en-usDjangohttps://www.djangoproject.com/s/img/site/hdr_logo.gifhttps://code.djangoproject.com/ticket/15238
Trac 1.2.2Carl MeyerMon, 07 Feb 2011 20:45:08 GMTcomponent, stage changedhttps://code.djangoproject.com/ticket/15238#comment:1
https://code.djangoproject.com/ticket/15238#comment:1
<ul>
<li><strong>component</strong>
changed from <em>Uncategorized</em> to <em>Database layer (models, ORM)</em>
</li>
<li><strong>stage</strong>
changed from <em>Unreviewed</em> to <em>Accepted</em>
</li>
</ul>
<p>
Nobody had anything to say in the mailing list thread, but on the face of it this seems like a pretty reasonable feature to me. There's no reason an installation of Django has to insist on claiming the entire table namespace for itself.
</p>
<p>
<a class="closed ticket" href="https://code.djangoproject.com/ticket/13176" title="#13176: Provide finer control over table name conventions (closed: wontfix)">#13176</a> was similar and closed wontfix, but largely on the basis of "added complexity," and that ticket was requesting much broader flexibility, which would have required much more added complexity than just a prefix.
</p>
<p>
The TABLE_PREFIX setting should be per-database (i.e. a key in the <code>DATABASES["db_alias"]</code> dict), not a global setting.
</p>
TicketDmitry GladkovMon, 07 Feb 2011 20:56:26 GMTattachment sethttps://code.djangoproject.com/ticket/15238
https://code.djangoproject.com/ticket/15238
<ul>
<li><strong>attachment</strong>
set to <em>patch.diff</em>
</li>
</ul>
<p>
first patch
</p>
TicketDmitry GladkovMon, 07 Feb 2011 20:58:20 GMTowner, status changedhttps://code.djangoproject.com/ticket/15238#comment:2
https://code.djangoproject.com/ticket/15238#comment:2
<ul>
<li><strong>owner</strong>
changed from <em>nobody</em> to <em>anonymous</em>
</li>
<li><strong>status</strong>
changed from <em>new</em> to <em>assigned</em>
</li>
</ul>
<p>
Sorry, I added that patch before I've seen your latest comment. I'm gonna rewrite that patch with per-database support instead of the global setting.
</p>
TicketDmitry GladkovMon, 07 Feb 2011 21:31:30 GMTowner, status changedhttps://code.djangoproject.com/ticket/15238#comment:3
https://code.djangoproject.com/ticket/15238#comment:3
<ul>
<li><strong>owner</strong>
changed from <em>anonymous</em> to <em>Carl Meyer</em>
</li>
<li><strong>status</strong>
changed from <em>assigned</em> to <em>new</em>
</li>
</ul>
<p>
I just tried to think it all through and it appears there is a problem with per-database setting.
</p>
<p>
Model metaclass has db_table property which should contain value disregarding of what database we are using. What value should it contain if we have different prefixes for different DBs?
</p>
TicketŁukasz RekuckiMon, 07 Feb 2011 21:35:19 GMTneeds_better_patch, has_patch, needs_tests changedhttps://code.djangoproject.com/ticket/15238#comment:4
https://code.djangoproject.com/ticket/15238#comment:4
<ul>
<li><strong>needs_better_patch</strong>
set
</li>
<li><strong>has_patch</strong>
set
</li>
<li><strong>needs_tests</strong>
set
</li>
</ul>
<p>
Your new patch should also include tests to show that the setting works as expected.
</p>
TicketCarl MeyerMon, 07 Feb 2011 22:47:23 GMThttps://code.djangoproject.com/ticket/15238#comment:5
https://code.djangoproject.com/ticket/15238#comment:5
<p>
Replying to <a class="ticket" href="https://code.djangoproject.com/ticket/15238#comment:3" title="Comment 3">dgl</a>:
</p>
<blockquote class="citation">
<p>
I just tried to think it all through and it appears there is a problem with per-database setting.
</p>
<p>
Model metaclass has db_table property which should contain value disregarding of what database we are using. What value should it contain if we have different prefixes for different DBs?
</p>
</blockquote>
<p>
Urg, that is a bit of a puzzler. I guess that means it has to be a global setting, but that feels wrong; the need for prefixed table names is a per-database need. Need to think this one over...
</p>
TicketCarl MeyerTue, 08 Feb 2011 15:06:58 GMTstatus changed; resolution sethttps://code.djangoproject.com/ticket/15238#comment:6
https://code.djangoproject.com/ticket/15238#comment:6
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>duplicate</em>
</li>
</ul>
<p>
In my prior art search, I missed <a class="closed ticket" href="https://code.djangoproject.com/ticket/5000" title="#5000: [patch] Table prefix (closed: wontfix)">#5000</a>, the only other ticket where this exact feature was proposed. (<a class="closed ticket" href="https://code.djangoproject.com/ticket/388" title="#388: enhancement: Prefix for django table names (closed: wontfix)">#388</a> and <a class="closed ticket" href="https://code.djangoproject.com/ticket/891" title="#891: defect: customize table name prefixes (closed: invalid)">#891</a> are similar, but not the same). <a class="closed ticket" href="https://code.djangoproject.com/ticket/5000" title="#5000: [patch] Table prefix (closed: wontfix)">#5000</a> brings up some additional problematic cases, such as apps that come bundled with initial SQL, which will break on any project with a global table-prefix setting applied.
</p>
<p>
Closing as duplicate of <a class="closed ticket" href="https://code.djangoproject.com/ticket/5000" title="#5000: [patch] Table prefix (closed: wontfix)">#5000</a>. I still think this is at its core a reasonable request, but I don't see how to implement it in a good way without breakage, and I'm not sure it's a high enough priority to be worth much fiddling. Further discussion should happen on the mailing list.
</p>
Ticket