[django channels] unrecognized arguments: --noworker

2017-11-10 Thread mccc
Hello,

I'm trying out channels, but I'm getting an "unrecognized arguments: 
--noworker" error when trying to execute a very simple "python manage.py 
runserver --noworker".
I found this file in the repository 

 that 
should patch the core command, but it appears as it's not working.
Am I doing something wrong? The official documentation doesn't seem to 
specify any special procedure to get that working..

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0ddf1be4-6b02-41a8-86d9-b46ac26ce829%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [django channels] unrecognized arguments: --noworker

2017-11-10 Thread mccc
nevermind, sorry about the spam: I had an old django-channels installation 
polluting my environment - I found out while gathering my libraries 
versions to post here...

On Friday, November 10, 2017 at 2:05:29 PM UTC+1, mccc wrote:
>
> Hello,
>
> I'm trying out channels, but I'm getting an "unrecognized arguments: 
> --noworker" error when trying to execute a very simple "python manage.py 
> runserver --noworker".
> I found this file in the repository 
> <https://github.com/django/channels/blob/master/channels/management/commands/runserver.py>
>  that 
> should patch the core command, but it appears as it's not working.
> Am I doing something wrong? The official documentation doesn't seem to 
> specify any special procedure to get that working..
>
> Thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d15af797-4a89-4255-8d63-292bc0a21beb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [OT] Is Trump planning to break the Internet?

2017-12-12 Thread mccc
I agree with Matthew's sentiment;

also, I'd like to point out that the words you (Larry) posted are not your 
own but are literally coming off of foxnews.com 

 (found 
also on telecoms.com 
,
 
by means of a "feature article" from a not-so-trustworthy consultancy 
group).
I do agree that the topic and the approach to the issue are not adequate 
for the group, but your (Larry's) attempt to "gain the high ground" fell 
_very_ short.

All the best,
Michele

On Monday, December 11, 2017 at 3:52:51 PM UTC+1, larry@gmail.com wrote:
>
> On Mon, Dec 11, 2017 at 9:24 AM, Matthew Pava  > wrote: 
> >>> Please keep your political rhetoric and irresponsible scaremongering 
> off this list. 
> > 
> >>> All the net neutrality repeal will do is restore some of the 
> permissionless innovation that allowed the internet to blossom in the first 
> place. 
> > 
> > Dear Larry, 
> > Please read what you just wrote.  On the one hand, you asked Etienne not 
> to share political rhetoric, and then you called Etienne's act one of 
> irresponsible scaremongering.  And then you had to have the last word in 
> this discussion by sharing your own political rhetoric about the topic. 
>  That's not right, and I'm not going to sit by and let that happen. 
> > 
> > The better way to handle it would have been a personal message to 
> Etienne asking that user not to post political rhetoric (in a nicer way 
> than you just did) and not make that message public. 
> > 
> > So here's an article about Net Neutrality: 
> > https://www.savetheinternet.com/net-neutrality-what-you-need-know-now 
>
> That article is from freepress.net, a very far left, statist group, 
> that feels the government should regulate, control and tax every 
> aspect of your lives. We do not need more government regulation, we 
> need less. A free market is always better. Net Neutrality is 
> censorship, and it's crony capitalism. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/80893af4-a5a6-494a-9829-5975ed48d7c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


on_delete not getting called when ForeignKey is a property

2019-03-14 Thread mccc
Hello,

I have set up this nice model:
class CustomGroup(models.Model):

name = models.CharField(max_length=255)
_parent = models.ForeignKey(
"self", on_delete=models.CASCADE, null=True, 
related_name="descendants", db_column="parent"
)
_depth = models.IntegerField(default=1)

@property
def parent(self):
return self._parent

@property
def depth(self):
return self._depth

@parent.setter
def parent(self, value):
if self == value:
raise ValueError("parent must be different from self")
p = value
while value is not None:
if self == value.parent:
raise ValueError("parent cannot be a descendant")
value = value.parent
self._parent = p
self.depth = (p.depth + 1) if p is not None else 1

@depth.setter
def depth(self, value):
if value > MAX_GROUPS_DEPTH:
raise ValueError("Too many nested groups")

for descendant in self.descendants.all():
descendant.depth = value + 1
descendant.save()
self._depth = value


and the CASCADE function is not getting fired when the parent gets deleted;
I tried adding another field without the property modifiers, and that 
worked as expected.

Is there any way I can have both my custom getter and setter, and the 
on_delete behaviour?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/292cfb9d-c605-46ef-bb4a-5d69a8ecbb6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: on_delete not getting called when ForeignKey is a property

2019-03-14 Thread mccc


On Thursday, March 14, 2019 at 4:22:15 PM UTC+1, Chetan Ganji wrote:
>
> Why do you need to do any calculations in the model code? 
>
> I would do any calculations in the views and store them using models. That 
> will remove the getters and setters from model. 
> Everything should work fine then.
>
> Hope it helps.
>

No, nothing would work fine: in that case I would need to remember 
constantly to either copy the code to handle the behaviour or make a call 
to *a view* each time and in any place that handles those fields.
Plus the tests would need to check over and over for the same behaviour 
every time the field was involved.

I'm sorry, but it really doesn't help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ed1853bb-402a-4688-9061-63054c44ce63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


multiple constraints not working in the db

2020-04-03 Thread mccc
Hello,

I'm having issues getting multiple constraints to work (in postgres, if it 
matters).
Here is the Meta:


class Meta:
constraints = [
CheckConstraint(
check=(Q(target_value__gt=0) & ~Q(target_metric=DEFAULT)) |
  (Q(enabled=False) |
   Q(status=IMPORTING) |
   Q(status=IMPORT_FAILURE)),
name="positive_target_value",
)
]


It would seem straightforward enough to me, but it ends up not working.
Here is the generated SQL (pulled from the db itself):
target_value > 0.0::double precision AND NOT target_metric::text = 'DEFAULT'
::text OR enabled = false OR status = 20 OR status = 30

And here is proof that it should actually work (pulled from a django 
console, where the conditions are copied from the migration file):

Folder.objects.filter(models.Q(models.Q(('target_value__gt', 0), 
models.Q(_negated=True, target_metric='DEFAULT')), ('enabled', False), 
('status', 20), ('status', 30), _connector='OR'))
web_1   | Out[5]: ]>
Folder.objects.filter(models.Q(models.Q(('target_value__gt', 0), 
models.Q(_negated=True, target_metric='**SOMETHING DIFFERENT**')), ('enabled', 
False), ('status', 20), ('status', 30), _connector='OR'))
web_1   | Out[7]: , < Folder: 
Folder thisFolderShouldNotHaveBeenCreted>]>


Anybody has any suggestion?
Btw, I also tried switching the first condition with the second one, 
effectively putting the AND at the bottom of the query, but it didn't seem 
to have any effect.

Thanks a lot.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dc746463-ef4c-4e17-9251-572ed374c0a4%40googlegroups.com.


Re: multiple constraints not working in the db

2020-04-03 Thread mccc
oh, forgot: versions are Python 3.7.6 and Django 2.2.11


On Friday, April 3, 2020 at 7:46:40 PM UTC+2, mccc wrote:
>
> Hello,
>
> I'm having issues getting multiple constraints to work (in postgres, if it 
> matters).
> Here is the Meta:
>
>
> class Meta:
> constraints = [
> CheckConstraint(
> check=(Q(target_value__gt=0) & ~Q(target_metric=DEFAULT)) |
>   (Q(enabled=False) |
>Q(status=IMPORTING) |
>Q(status=IMPORT_FAILURE)),
> name="positive_target_value",
> )
> ]
>
>
> It would seem straightforward enough to me, but it ends up not working.
> Here is the generated SQL (pulled from the db itself):
> target_value > 0.0::double precision AND NOT target_metric::text = 
> 'DEFAULT'::text OR enabled = false OR status = 20 OR status = 30
>
> And here is proof that it should actually work (pulled from a django 
> console, where the conditions are copied from the migration file):
>
> Folder.objects.filter(models.Q(models.Q(('target_value__gt', 0), 
> models.Q(_negated=True, target_metric='DEFAULT')), ('enabled', False), 
> ('status', 20), ('status', 30), _connector='OR'))
> web_1   | Out[5]: ]>
> Folder.objects.filter(models.Q(models.Q(('target_value__gt', 0), 
> models.Q(_negated=True, target_metric='**SOMETHING DIFFERENT**')), 
> ('enabled', False), ('status', 20), ('status', 30), _connector='OR'))
> web_1   | Out[7]: , < 
> Folder: Folder thisFolderShouldNotHaveBeenCreted>]>
>
>
> Anybody has any suggestion?
> Btw, I also tried switching the first condition with the second one, 
> effectively putting the AND at the bottom of the query, but it didn't seem 
> to have any effect.
>
> Thanks a lot.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d11734fe-1691-419e-bf87-792981315901%40googlegroups.com.


Prefetch object with to_attr set to the same name as the field triggers rows deletions

2015-11-05 Thread mccc
I'm using a Prefetch object to follow some GenericRelation, and I was 
playing around with the to_attr parameter;
I had the DB debug turned on, as I was checking whether it was making any 
difference, and I started noticing some DELETE statements on the remote 
table, so I started investigating.
It looks like those deletions are triggered within the prefetch process 
when the to_attr is set to the same name as the field; also, it does not 
seem to happen if the relationship is not a generic one.
While this usage is presumably wrong, it is not mentioned anywhere in the 
docs; also, I think that deleting rows from the database is a somewhat 
extreme way to educate users :)
Can someone enlighten me on what's going on here?

Thank you very much.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c1680410-8bb7-4358-a3ee-44f65cdc7c70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


DataError on get_or_create with nullable fields

2015-12-02 Thread mccc
(this is mostly copied/pasted from my comment on an eight-years-old issue 
here <https://code.djangoproject.com/ticket/6563>)

I cannot get the get_or_create operation to create non-existing object with 
nullable field, getting a `DataError: integer out of range` error.

The query goes like so: 
`Test.objects.get_or_create(**{u'device_preference__isnull': True, 
u'test_type': u'TextTest', u'master_id': 1234, u'testset_id__isnull': 
True})` where `device_preference` is a nullable PositiveIntegerField and 
`testset_id` is a ForeignKey.

Attached traceback shows that the issue happens on creation, I believe.

{{{
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/manager.py",
 
line 127, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/query.py",
 
line 407, in get_or_create
return self._create_object_from_params(lookup, params)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/query.py",
 
line 439, in _create_object_from_params
obj = self.create(**params)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/query.py",
 
line 348, in create
obj.save(force_insert=True, using=self.db)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/base.py",
 
line 734, in save
force_update=force_update, update_fields=update_fields)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/base.py",
 
line 762, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, 
update_fields)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/base.py",
 
line 846, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, 
raw)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/base.py",
 
line 885, in _do_insert
using=using, raw=raw)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/manager.py",
 
line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/query.py",
 
line 920, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
 
line 974, in execute_sql
cursor.execute(sql, params)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/backends/utils.py",
 
line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/backends/utils.py",
 
line 64, in execute
return self.cursor.execute(sql, params)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/utils.py", 
line 98, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
  File 
"/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/backends/utils.py",
 
line 64, in execute
return self.cursor.execute(sql, params)
DataError: integer out of range
}}}

I have not reopened the issue, just because, but I'd welcome any possible 
comment.
Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/15e8559a-dc36-492e-a49c-bd1d20135238%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: DataError on get_or_create with nullable fields

2015-12-03 Thread mccc
Well turns out it was actually the `master_id` foreign key that was being 
set to garbage, hence the DataError;
everything besides me is working as intended.

cheers

On Wednesday, December 2, 2015 at 6:03:22 PM UTC+1, mccc wrote:
>
> (this is mostly copied/pasted from my comment on an eight-years-old issue 
> here <https://code.djangoproject.com/ticket/6563>)
>
> I cannot get the get_or_create operation to create non-existing object 
> with nullable field, getting a `DataError: integer out of range` error.
>
> The query goes like so: 
> `Test.objects.get_or_create(**{u'device_preference__isnull': True, 
> u'test_type': u'TextTest', u'master_id': 1234, u'testset_id__isnull': 
> True})` where `device_preference` is a nullable PositiveIntegerField and 
> `testset_id` is a ForeignKey.
>
> Attached traceback shows that the issue happens on creation, I believe.
>
> {{{
> Traceback (most recent call last):
>   File "", line 1, in 
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/manager.py",
>  
> line 127, in manager_method
> return getattr(self.get_queryset(), name)(*args, **kwargs)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/query.py",
>  
> line 407, in get_or_create
> return self._create_object_from_params(lookup, params)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/query.py",
>  
> line 439, in _create_object_from_params
> obj = self.create(**params)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/query.py",
>  
> line 348, in create
> obj.save(force_insert=True, using=self.db)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/base.py",
>  
> line 734, in save
> force_update=force_update, update_fields=update_fields)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/base.py",
>  
> line 762, in save_base
> updated = self._save_table(raw, cls, force_insert, force_update, 
> using, update_fields)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/base.py",
>  
> line 846, in _save_table
> result = self._do_insert(cls._base_manager, using, fields, update_pk, 
> raw)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/base.py",
>  
> line 885, in _do_insert
> using=using, raw=raw)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/manager.py",
>  
> line 127, in manager_method
> return getattr(self.get_queryset(), name)(*args, **kwargs)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/query.py",
>  
> line 920, in _insert
> return query.get_compiler(using=using).execute_sql(return_id)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
>  
> line 974, in execute_sql
> cursor.execute(sql, params)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/backends/utils.py",
>  
> line 79, in execute
> return super(CursorDebugWrapper, self).execute(sql, params)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/backends/utils.py",
>  
> line 64, in execute
> return self.cursor.execute(sql, params)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/utils.py", 
> line 98, in __exit__
> six.reraise(dj_exc_type, dj_exc_value, traceback)
>   File 
> "/Users/mccc/Dev/venvs/tools/lib/python2.7/site-packages/django/db/backends/utils.py",
>  
> line 64, in execute
> return self.cursor.execute(sql, params)
> DataError: integer out of range
> }}}
>
> I have not reopened the issue, just because, but I'd welcome any possible 
> comment.
> Thank you.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c27fdf3b-ecc4-4245-b551-e7b28be7b90a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


queryset appears empty in debugger during testing, but not in console

2018-06-18 Thread mccc
Hello,

I'm testing REST APIs with rest_framework.test.APITestCase, using their 
client for making requests and model_mommy for creating objects in the 
setUp() method.
The general working is quite simple: the view is supposed to fetch a User 
and an object, and assign permissions for the former to the latter by means 
of django-guardian's assign_perm; the test creates a user and a group in 
the setUp method, then the actual test performs a POST passing their pk's 
as payload.
The issue I'm seeing, is that when the 
User.objects.filter(pk__in=people_ids) instruction is executed, the value I 
see in the debugger is that of an empty queryset, while if I type the exact 
same line in a console connected to the same session as the debugger I see 
the actual value being found.
Then the view gets to the assign_perm instruction, and it crashes with 
an IndexError: list index out of range error on the first evaluation of the 
queryset itself, which happens on the for loop at line 247 in the file 
core.py of the django-guardian library.

Is there something obvious that I should be looking at, because I really 
cannot wrap my head around this.

Thanks,
Michele

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bf0050d0-525a-4844-834c-6c3eff2c04b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Meta indexes and makemigrations

2024-12-05 Thread mccc
Turns out there was a tiny class Meta at the very bottom of the very big 
model, obfuscating mine defining the index.. Something not even ChatGPT 
could imagine!

On Thursday, December 5, 2024 at 12:31:01 PM UTC+1 RANGA BHARATH JINKA 
wrote:

> Hi,
>
> The issue is that partial indexes with conditions (condition attribute in 
> models.Index) were introduced in *Django 3.2*, but they rely on the 
> database backend's ability to support them. PostgreSQL does support partial 
> indexes, so that part should be fine. However, your problem likely stems 
> from the following points:
> 1. *Condition on channel_type Value* 
>
> The condition models.Q(channel_type="42") is valid in Python, but 
> PostgreSQL requires conditions to work with literal values that match the 
> column type. If channel_type is a CharField, "42" is fine. However, 
> ensure that the value and type match your database schema.
>
>- Example: If channel_type is actually an integer-like value stored in 
>a CharField, ensure "42" matches the expected format. 
>
> --
> 2. *Potential Issue with Makemigrations* 
>
> Even if the code is correct, makemigrations might not detect the change 
> in the Meta class because migrations only track model-level changes. If 
> makemigrations doesn’t pick up the index:
>
>- 
>
>*Manually Generate the Migration:* Use makemigrations with the --empty 
>flag and define the index manually.
>
>python manage.py makemigrations --empty your_app_name
>
>Then, in the generated migration file, define the index:
>
>from django.db import migrations, models
>import django.db.models.expressions
>
>class Migration(migrations.Migration):
>dependencies = [
>('your_app_name', 'previous_migration'),
>]
>
>operations = [
>migrations.AddIndex(
>model_name='episode',
>index=models.Index(
>name='ch_last_seen_date',
>fields=['last_seen_date'],
>condition=models.Q(channel_type='42'),
>),
>),
>]
>
>
> --
> 3. *Check Your Environment* 
>
> Ensure your Django project environment is up-to-date and consistent:
>
>- Confirm your django.db.backends.postgresql version supports the 
>feature. 
>- Run python manage.py showmigrations to ensure your migrations are 
>applied. 
>
> --
> Debugging Steps 
>
>1. 
>
>Double-check the condition syntax:
>
>condition=models.Q(channel_type='42')
>
>Ensure channel_type and '42' match your schema's type expectations.
>2. 
>
>Confirm makemigrations is running in the correct app and picking up 
>changes:
>
>python manage.py makemigrations your_app_name
>
>3. 
>
>Review your migration file for errors or omissions.
>
> If the issue persists after these steps, consider upgrading to the latest 
> Django version for potential bug fixes in migration handling. 
>
> On Thu, Dec 5, 2024 at 4:11 PM mccc  wrote:
>
>> Hello,
>>
>> We want to have a partial index (db backend is Postgres) on a 
>> datetimefield, so we added this code to the Meta class:
>>
>> class Episode(models.Model):
>> channel_type = models.CharField(max_length=16, choices=CHANNEL_TYPES)
>> last_seen_date = models.DateTimeField(auto_now_add=True)
>> class Meta:
>> indexes = [
>> models.Index(
>> name="ch_last_seen_date",
>> fields=["last_seen_date"],
>> condition=models.Q(channel_type="42"),
>> ),
>> ]
>>
>> The problem is that makemigrations doesn't seem to recognize it.
>> What could be the problem? We're on Django 3.2, which I know is old but 
>> as per the documentation this should be fine..
>>
>> Thanks
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To view this discussion visit 
>> https://groups.google.com/d/msgid/django-users/ee6aa542-aac2-4c78-821b-54d597c80b7cn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/ee6aa542-aac2-4c78-821b-54d597c80b7cn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Thanks and Regards
>
> J. Ranga Bharath
> cell: 9110334114
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/django-users/b8323896-aa90-46f4-af45-3b0eaa6ded79n%40googlegroups.com.


Meta indexes and makemigrations

2024-12-05 Thread mccc
Hello,

We want to have a partial index (db backend is Postgres) on a 
datetimefield, so we added this code to the Meta class:

class Episode(models.Model):
channel_type = models.CharField(max_length=16, choices=CHANNEL_TYPES)
last_seen_date = models.DateTimeField(auto_now_add=True)
class Meta:
indexes = [
models.Index(
name="ch_last_seen_date",
fields=["last_seen_date"],
condition=models.Q(channel_type="42"),
),
]

The problem is that makemigrations doesn't seem to recognize it.
What could be the problem? We're on Django 3.2, which I know is old but as 
per the documentation this should be fine..

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/django-users/ee6aa542-aac2-4c78-821b-54d597c80b7cn%40googlegroups.com.