If you get this error during migration you likely have some existing Stock rows
in your database with quantity that is less than 0. If this site is in
production already, you'll need to create a data migration to change your
negative quantities to zero.
https://docs.djangoproject.com/en/4.1/top
I managed to remove the error,
I had a negative stock in my DB.
Thanks a lot for the help.
On that note, I was also trying to get the dispensed from stock
I was trying to do this but I don't think it can work since there is
already a foreign key at Dispense model fetching drug_id from stock.
W
Hello,
Sorry the error is:
django.db.utils.IntegrityError: CHECK constraint failed: quantity
On Thu, Sep 1, 2022 at 3:45 AM Ryan Nowakowski wrote:
> I don't see any error. Did you forget to post it?
>
> On August 31, 2022 5:57:32 AM CDT, tech george
> wrote:
>>
>> Hello,
>>
>> Sorry for the
I don't think you need that constraint after using the PositiveIntegerField
.
On Thu, 1 Sep 2022, 02:45 Ryan Nowakowski, wrote:
> I don't see any error. Did you forget to post it?
>
> On August 31, 2022 5:57:32 AM CDT, tech george
> wrote:
>>
>> Hello,
>>
>> Sorry for the late reply.
>>
>> I c
I don't see any error. Did you forget to post it?
On August 31, 2022 5:57:32 AM CDT, tech george wrote:
>Hello,
>
>Sorry for the late reply.
>
>I changed the models as below and added checkConstraint , But when I
>migrate I get the below error.
>
>What am I still doing wrong?
>
>class Stock(model
Hello,
Sorry for the late reply.
I changed the models as below and added checkConstraint , But when I
migrate I get the below error.
What am I still doing wrong?
class Stock(models.Model):
quantity = models.PositiveIntegerField(default='0', blank=True,
null=True)
reorder_level = models.
I don't see where you define the quantity variable, should that be
instance.quantity? Also, presumably you want to check if quantity is
greater than or equal to qu rather than 0.
Try changing `if quantity > 0` to `if instance.quantity >= qu`
On Tuesday, August 30, 2022 at 3:44:51 PM UTC+1 Ryan
On Mon, Aug 29, 2022 at 05:18:39PM +0300, tech george wrote:
> Please help crack the below code, I want to prevent negative stock, and if
> the stock is == 0, deduct it from reorder_level instead.
> Currently, the stock goes negative.
>
> models.py
>
> class Stock(models.Model):
> quantity =
As a start, the logic checks for the model should not be in views.py but
rather with the model object (in models.py). You can extend the save()
method, for example, and add the checks there.
See:
* https://docs.djangoproject.com/en/4.1/ref/models/instances/#saving-objects
*
https://docs.djang
Hello,
Please help crack the below code, I want to prevent negative stock, and if
the stock is == 0, deduct it from reorder_level instead.
Currently, the stock goes negative.
models.py
class Stock(models.Model):
quantity = models.IntegerField(default='0', blank=True, null=True)
reorder_l
10 matches
Mail list logo