Re: [Django] #31167: Unable to delete or modify a constraint using model Meta. (was: Unable to delete or modify a constraint using model Meta)

2020-01-14 Thread Django
#31167: Unable to delete or modify a constraint using model Meta.
+--
 Reporter:  BITSOLVER   |Owner:  nobody
 Type:  Bug |   Status:  closed
Component:  Migrations  |  Version:  master
 Severity:  Normal  |   Resolution:  worksforme
 Keywords:  Migrations, unique  | Triage Stage:  Unreviewed
Has patch:  0   |  Needs documentation:  0
  Needs tests:  0   |  Patch needs improvement:  0
Easy pickings:  0   |UI/UX:  0
+--
Changes (by felixxm):

 * status:  new => closed
 * type:  Uncategorized => Bug
 * version:  2.2 => master
 * resolution:   => worksforme


Comment:

 Thanks for this ticket, however I'm not able to reproduce this issue,
 everything works for me.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

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


Re: [Django] #31167: Unable to delete or modify a constraint using model Meta

2020-01-14 Thread Django
#31167: Unable to delete or modify a constraint using model Meta
+--
 Reporter:  BITSOLVER   |Owner:  nobody
 Type:  Uncategorized   |   Status:  new
Component:  Migrations  |  Version:  2.2
 Severity:  Normal  |   Resolution:
 Keywords:  Migrations, unique  | Triage Stage:  Unreviewed
Has patch:  0   |  Needs documentation:  0
  Needs tests:  0   |  Patch needs improvement:  0
Easy pickings:  0   |UI/UX:  0
+--

Comment (by BITSOLVER):

 On further investigation a previous migration had:

 {{{
 # Generated by Django 2.2.5 on 2019-09-30 13:40

 from django.db import migrations, models


 class Migration(migrations.Migration):

 dependencies = [
 ('venue', '0008_standardcommunitycentreprice_venues'),
 ]

 operations = [
 migrations.RemoveConstraint(
 model_name='standardcommunitycentrepricelist',
 name='unique_standard_community_price_list',
 ),
 migrations.AddConstraint(
 model_name='standardcommunitycentrepricelist',
 constraint=models.UniqueConstraint(fields=('customer_type',
 'customer'), name='unique_standard_community_price_list'),
 ),
 migrations.RemoveField(
 model_name='standardcommunitycentrepricelist',
 name='code',
 ),
 migrations.AlterField(
 model_name='standardcommunitycentreprice',
 name='day_of_week',
 field=models.IntegerField(choices=[(None, 'Any'), (1,
 'Monday'), (2, 'Tuesday'), (3, 'Wednesday'), (4, 'Thursday'), (5,
 'Friday'), (6, 'Saturday'), (7, 'Sunday')], null=True),
 ),
 ]

 }}}

 And if I delete remove constraint from the latest migration then run
 migrate then the migrations completes.

 If I then run makemigrations venue again it creates a remove constraint,
 run again then it creates and add migration back.

 Everything is back in sync now, I just wonder if something odd went on
 with the order of operations for remove & add unique constraints?

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

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


[Django] #31167: Unable to delete or modify a constraint using model Meta

2020-01-14 Thread Django
#31167: Unable to delete or modify a constraint using model Meta
-+-
   Reporter:  BITSOLVER  |  Owner:  nobody
   Type: | Status:  new
  Uncategorized  |
  Component: |Version:  2.2
  Migrations |
   Severity:  Normal |   Keywords:  Migrations, unique
   Triage Stage: |  Has patch:  0
  Unreviewed |
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+-
 I have the following model in a "venue" app on my project:

 {{{
 class StandardCommunityCentrePriceList(models.Model):

 class Meta:
 constraints = [
 models.UniqueConstraint(
 fields=["customer_type", "customer"],
 name="unique_standard_community_price_list"
 )
 ]

 customer_type = models.ForeignKey("customer.CustomerType", null=True,
 related_name="+", on_delete=CASCADE, blank=True)
 customer = models.ForeignKey("customer.Customer", null=True,
 related_name="+", on_delete=CASCADE, blank=True)
 price_type = models.CharField(max_length=6, null=False,
 choices=STANDARD_COMMUNITY_CENTRE_PRICE_TYPE_CHOICES)
 description = models.CharField(max_length=80, null=False)
 tax_inclusive = models.BooleanField(verbose_name=_("Tax Inclusive"),
 null=False,
 default=False)  # False means
 charges are net of tax, True means charges are inclusive of tax

 @property
 def is_hourly(self):
 return self.price_type == STANDARD_COMMUNITY_CENTRE_PRICE_HOURLY

 @property
 def is_fixed(self):
 return self.price_type == STANDARD_COMMUNITY_CENTRE_PRICE_FIXED

 def clone_price_list(self, source_id):
 source_price_list =
 StandardCommunityCentrePriceList.objects.get(id=source_id)
 for price_range in source_price_list.ranges.all():
 cloned_range =
 StandardCommunityCentrePriceRange.objects.create(
 price_list=self,
 effective_from_date=price_range.effective_from_date,
 start_date=price_range.start_date,
 end_date=price_range.end_date
 )
 cloned_range.clone_prices(price_range)

 def __str__(self):
 return "%s" % self.description
 }}}

 When I change the constraint to:

 {{{
 class Meta:
 constraints = [
 models.UniqueConstraint(
 fields=["customer_type", "customer", "price_type"],
 name="unique_standard_community_price_list"
 )
 ]
 }}}

 I run makemigrations venue and get:

 Output:

 {{{
 Migrations for 'venue':
   venue/migrations/0010_auto_20200114_1457.py
 - Remove constraint unique_standard_community_price_list from model
 standardcommunitycentrepricelist
 - Create constraint unique_standard_community_price_list on model
 standardcommunitycentrepricelist

 Process finished with exit code 0
 }}}

 The migration file contains:

 {{{
 # Generated by Django 2.2.9 on 2020-01-14 14:57

 from django.db import migrations, models


 class Migration(migrations.Migration):

 dependencies = [
 ('venue', '0009_auto_20190930_1440'),
 ]

 operations = [
 migrations.RemoveConstraint(
 model_name='standardcommunitycentrepricelist',
 name='unique_standard_community_price_list',
 ),
 migrations.AddConstraint(
 model_name='standardcommunitycentrepricelist',
 constraint=models.UniqueConstraint(fields=('customer_type',
 'customer', 'price_type'), name='unique_standard_community_price_list'),
 ),
 ]

 }}}


 But when I run migrate I get the following error:

 {{{
 Operations to perform:
   Apply all migrations: _holidaypark, _kennels, accommodation, admin,
 auth, auth_ext, avalonimport, bookings, breeds, captcha, configuration,
 contact, contenttypes, core, countries, customer, django_celery_beat,
 django_celery_results, emailer, entitymapper, eventlog, extras,
 holiday_dates, invoicing, ipn, notes, pets, register_customer, resources,
 sessions, statuses, supplier, task_ext, tax, venue
 Running migrations:
   Applying venue.0010_auto_20200114_1457...Traceback (most recent call
 last):
   File "/Users/steven/.virtualenvs/bookingsmanager-3.6/lib/python3.6/site-
 packages/django/db/backends/utils.py", line 84, in _execute
 return self.cursor.execute(sql, params)
 psycopg2.errors.UndefinedObject: constraint
 "unique_standard_community_price_list" of relation
 "venue_standardcommunitycentrepricelist" does not exist


 The above exception was the direct cause of the following exception: