Opened 11 months ago
Closed 11 months ago
#36024 closed Bug (invalid)
Run separately Django ORM set model._meta.db_table problem
| Reported by: | ygbh | Owned by: | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 5.1 |
| Severity: | Normal | Keywords: | |
| Cc: | ygbh | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
hello,use django ORM single run,exmaple:https://docs.djangoproject.com/en/5.1/topics/settings/#either-configure-or-django-settings-module-is-required
set db_table ref error.
class MyManager(models.Manager):
_my_table_name = None
def get_queryset(self):
return super().get_queryset()
def table_name(self, datetime_obj: Union[datetime, str]):
if not self._my_table_name:
MyManager._my_table_name = self.model._meta.db_table
if isinstance(datetime_obj, datetime):
self.model._meta.db_table: str = MyManager._my_table_name + '_' + datetime_obj.strftime('%Y_%m_%d')
else:
self.model._meta.db_table: str = MyManager._my_table_name + '_' + datetime_obj
self.model._meta.verbose_name_raw = None
return self
MySQLDB module print Query SQL:
SELECT `record_gateway_2024_12_18`.`id`, `record_gateway_2024_12_18`.`label`, `record_gateway_2024_12_18`.`mobile`, `record_gateway_2024_12_18`.`nation_code`, CONCAT_WS( '', `record_gateway_2024_12_18`.`nation_code`, `record_gateway_2024_12_18`.`mobile` ) AS `phone` FROM `record_gateway_2024_12_17` WHERE CONCAT_WS( '', `record_gateway_2024_12_18`.`nation_code`, `record_gateway_2024_12_18`.`mobile` ) = '86110' ORDER BY `record_gateway_2024_12_18`.`recv_time` DESC LIMIT 1
table_name is set success【record_gateway_2024_12_17】
table_name ref var set fail【record_gateway_2024_12_18】
Running the Django project directly is normal.
Django ORM has problems running alone.
Change History (3)
comment:1 by , 11 months ago
| Type: | Uncategorized → Bug |
|---|
comment:2 by , 11 months ago
| Summary: | model._meta.db_table → Run separately Django ORM set model._meta.db_table problem |
|---|
comment:3 by , 11 months ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Hello, That's some inventive code you wrote. Maybe you can make it work and find some way to set
db_tabledynamically, but it certainly isn't a supported configuration that identifies a bug in Django.To get help, use TicketClosingReasons/UseSupportChannels instead.