not a valid UUID.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

not a valid UUID.

Benedict Uwazie
I added a field called transaction_id in my models.py I want that field to be used to track every transaction on my "DuesLevy" model I imported uuid to this to happen, but each time I migrate I get this error.
How do i prevent this error from occurring each time I migrate (python manage.py migrate) File "C:\Users\Benedict\Miniconda3\envs\django3\lib\site-packages\django\db\models\fields\__init__.py", line 2344, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'13615773708697' is not a valid UUID."]

my models.py
trans_id = uuid.uuid4()
trans_str = trans_id.int
pass_trans = str(trans_str)[:12]
cast_trans = int(pass_trans)
class DuesLevy(models.Model):
    class_of_dues = models.CharField(max_length=30default=options.CHOOSE, choices=options.CLASS_OF_DUES, blank=True)
    payment_circle = models.CharField(max_length=30default=options.CHOOSE, choices=options.PAYMENT_CIRCLE)
    payment_option = models.CharField(max_length=30default=options.CHOOSE, choices=options.PAYMENT_OPTION)
    amount = models.DecimalField(max_digits=8decimal_places=2)
    transaction_id = models.(max_length=100, unique=True, null=True, blank=True, editable=False, default=cast_trans)
    payment_channel = models.CharField(max_length=30default=options.CHOOSE, choices=options.PAYMENT_CHANNEL_TYPE)
    payment_date = models.DateField()
    date_recorded = models.DateTimeField(auto_now_add=True)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    description = models.TextField(blank=Truenull=True)

    def __str__(self):
        return self.amount
    
  
    def get_absolute_url(self):
        return reverse('backend:detail_dues'kwargs={'pk'self.id})

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aa5a912f-e1fd-483b-b13b-bc9fdd9f1352%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: not a valid UUID.

Benedict Uwazie


On Sunday, 3 May 2020 01:38:16 UTC+1, Benedict Uwazie wrote:
I added a field called transaction_id in my models.py I want that field to be used to track every transaction on my "DuesLevy" model I imported uuid to this to happen, but each time I migrate I get this error.
How do i prevent this error from occurring each time I migrate (python manage.py migrate) File "C:\Users\Benedict\Miniconda3\envs\django3\lib\site-packages\django\db\models\fields\__init__.py", line 2344, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'13615773708697' is not a valid UUID."]

my models.py
trans_id = uuid.uuid4()
trans_str = <a href="http://trans_id.int" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftrans_id.int\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFLnRKPrOh9DNDAMgMz9F1T3lAG7Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftrans_id.int\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFLnRKPrOh9DNDAMgMz9F1T3lAG7Q&#39;;return true;">trans_id.int
pass_trans = str(trans_str)[:12]
cast_trans = int(pass_trans)
class DuesLevy(models.Model):
    class_of_dues = models.CharField(max_length=30default=options.CHOOSE, choices=options.CLASS_OF_DUES, blank=True)
    payment_circle = models.CharField(max_length=30default=options.CHOOSE, choices=options.PAYMENT_CIRCLE)
    payment_option = models.CharField(max_length=30default=options.CHOOSE, choices=options.PAYMENT_OPTION)
    amount = models.DecimalField(max_digits=8decimal_places=2)
    transaction_id = models.UUIDField(max_length=100, unique=Truenull=True, blank=Trueeditable=False, default=cast_trans)
    payment_channel = models.CharField(max_length=30default=options.CHOOSE, choices=options.PAYMENT_CHANNEL_TYPE)
    payment_date = models.DateField()
    date_recorded = models.DateTimeField(auto_now_add=True)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    description = models.TextField(blank=Truenull=True)

    def __str__(self):
        return self.amount
    
  
    def get_absolute_url(self):
        return reverse('backend:detail_dues'kwargs={'pk'self.id})

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: not a valid UUID.

Motaz Hejaze
default=cast_trans cast_trans = int(pass_trans)
UUID is string not int

On Sun, May 3, 2020 at 4:05 AM Benedict Uwazie <[hidden email]> wrote:


On Sunday, 3 May 2020 01:38:16 UTC+1, Benedict Uwazie wrote:
I added a field called transaction_id in my models.py I want that field to be used to track every transaction on my "DuesLevy" model I imported uuid to this to happen, but each time I migrate I get this error.
How do i prevent this error from occurring each time I migrate (python manage.py migrate) File "C:\Users\Benedict\Miniconda3\envs\django3\lib\site-packages\django\db\models\fields\__init__.py", line 2344, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'13615773708697' is not a valid UUID."]

my models.py
trans_id = uuid.uuid4()
trans_str = trans_id.int
pass_trans = str(trans_str)[:12]
cast_trans = int(pass_trans)
class DuesLevy(models.Model):
    class_of_dues = models.CharField(max_length=30default=options.CHOOSE, choices=options.CLASS_OF_DUES, blank=True)
    payment_circle = models.CharField(max_length=30default=options.CHOOSE, choices=options.PAYMENT_CIRCLE)
    payment_option = models.CharField(max_length=30default=options.CHOOSE, choices=options.PAYMENT_OPTION)
    amount = models.DecimalField(max_digits=8decimal_places=2)
    transaction_id = models.UUIDField(max_length=100, unique=True, null=True, blank=True, editable=False, default=cast_trans)
    payment_channel = models.CharField(max_length=30default=options.CHOOSE, choices=options.PAYMENT_CHANNEL_TYPE)
    payment_date = models.DateField()
    date_recorded = models.DateTimeField(auto_now_add=True)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    description = models.TextField(blank=Truenull=True)

    def __str__(self):
        return self.amount
    
  
    def get_absolute_url(self):
        return reverse('backend:detail_dues'kwargs={'pk'self.id})

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHV4E-fS__yc-mkPjTvkrNuRUarogCeuafRjss5B5ZYJxmckZQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: not a valid UUID.

Benedict Uwazie
Still facing the same issue

On Sunday, 3 May 2020 03:27:46 UTC+1, Motaz Hejaze wrote:
default=cast_trans cast_trans = int(pass_trans)
UUID is string not int

On Sun, May 3, 2020 at 4:05 AM Benedict Uwazie <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="1_GuQymdBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">nonw...@...> wrote:


On Sunday, 3 May 2020 01:38:16 UTC+1, Benedict Uwazie wrote:
I added a field called transaction_id in my models.py I want that field to be used to track every transaction on my "DuesLevy" model I imported uuid to this to happen, but each time I migrate I get this error.
How do i prevent this error from occurring each time I migrate (python manage.py migrate) File "C:\Users\Benedict\Miniconda3\envs\django3\lib\site-packages\django\db\models\fields\__init__.py", line 2344, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'13615773708697' is not a valid UUID."]

my models.py
trans_id = uuid.uuid4()
trans_str = <a href="http://trans_id.int" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftrans_id.int\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFLnRKPrOh9DNDAMgMz9F1T3lAG7Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftrans_id.int\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFLnRKPrOh9DNDAMgMz9F1T3lAG7Q&#39;;return true;">trans_id.int
pass_trans = str(trans_str)[:12]
cast_trans = int(pass_trans)
class DuesLevy(models.Model):
    class_of_dues = models.CharField(max_length=30default=options.CHOOSE, choices=options.CLASS_OF_DUES, blank=True)
    payment_circle = models.CharField(max_length=30default=options.CHOOSE, choices=options.PAYMENT_CIRCLE)
    payment_option = models.CharField(max_length=30default=options.CHOOSE, choices=options.PAYMENT_OPTION)
    amount = models.DecimalField(max_digits=8decimal_places=2)
    transaction_id = models.UUIDField(max_length=100unique=True, null=True, blank=True, editable=False, default=cast_trans)
    payment_channel = models.CharField(max_length=30default=options.CHOOSE, choices=options.PAYMENT_CHANNEL_TYPE)
    payment_date = models.DateField()
    date_recorded = models.DateTimeField(auto_now_add=True)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    description = models.TextField(blank=Truenull=True)

    def __str__(self):
        return self.amount
    
  
    def get_absolute_url(self):
        return reverse('backend:detail_dues'kwargs={'pk'self.id})

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="1_GuQymdBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/56e9691b-bb0f-4d27-8f97-def14e34217d%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: not a valid UUID.

Nomeh Uchenna Gabriel
On Sunday, May 3, 2020 at 9:10:28 AM UTC+1, Benedict Uwazie wrote:

> Still facing the same issue
>
> On Sunday, 3 May 2020 03:27:46 UTC+1, Motaz Hejaze  wrote:
> default=cast_trans
> cast_trans = int(pass_trans)
>
> UUID is string not int
>
>
> On Sun, May 3, 2020 at 4:05 AM Benedict Uwazie <[hidden email]> wrote:
>
>
>
> On Sunday, 3 May 2020 01:38:16 UTC+1, Benedict Uwazie  wrote:
>
> I added a field called transaction_id in my models.py I want that field to be used to track every transaction on my "DuesLevy" model I imported uuid to this to happen, but each time I migrate I get this error.
> How do i prevent this error from occurring each time I migrate (python manage.py migrate) File "C:\Users\Benedict\Miniconda3\envs\django3\lib\site-packages\django\db\models\fields\__init__.py", line 2344, in to_python
> params={'value': value},
> django.core.exceptions.ValidationError: ["'13615773708697' is not a valid UUID."]
>
>
> my models.py
>
>
> trans_id = uuid.uuid4()
> trans_str = trans_id.int
> pass_trans = str(trans_str)[:12]
> cast_trans = int(pass_trans)
> class DuesLevy(models.Model):
>     class_of_dues = models.CharField(max_length=30, default=options.CHOOSE, choices=options.CLASS_OF_DUES, blank=True)
>     payment_circle = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CIRCLE)
>     payment_option = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_OPTION)
>     amount = models.DecimalField(max_digits=8, decimal_places=2)
>     transaction_id = models.UUIDField(max_length=100, unique=True, null=True, blank=True, editable=False, default=cast_trans)
>     payment_channel = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CHANNEL_TYPE)
>     payment_date = models.DateField()
>     date_recorded = models.DateTimeField(auto_now_add=True)
>     user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
>     description = models.TextField(blank=True, null=True)
>
>     def __str__(self):
>         return self.amount
>     
>   
>     def get_absolute_url(self):
>         return reverse('backend:detail_dues', kwargs={'pk': self.id})
>
>
>
>
>
>
> --
>
> 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 [hidden email].
>
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com.


On Sunday, May 3, 2020 at 9:10:28 AM UTC+1, Benedict Uwazie wrote:

> Still facing the same issue
>
> On Sunday, 3 May 2020 03:27:46 UTC+1, Motaz Hejaze  wrote:
> default=cast_trans
> cast_trans = int(pass_trans)
>
> UUID is string not int
>
>
> On Sun, May 3, 2020 at 4:05 AM Benedict Uwazie <[hidden email]> wrote:
>
>
>
> On Sunday, 3 May 2020 01:38:16 UTC+1, Benedict Uwazie  wrote:
>
> I added a field called transaction_id in my models.py I want that field to be used to track every transaction on my "DuesLevy" model I imported uuid to this to happen, but each time I migrate I get this error.
> How do i prevent this error from occurring each time I migrate (python manage.py migrate) File "C:\Users\Benedict\Miniconda3\envs\django3\lib\site-packages\django\db\models\fields\__init__.py", line 2344, in to_python
> params={'value': value},
> django.core.exceptions.ValidationError: ["'13615773708697' is not a valid UUID."]
>
>
> my models.py
>
>
> trans_id = uuid.uuid4()
> trans_str = trans_id.int
> pass_trans = str(trans_str)[:12]
> cast_trans = int(pass_trans)
> class DuesLevy(models.Model):
>     class_of_dues = models.CharField(max_length=30, default=options.CHOOSE, choices=options.CLASS_OF_DUES, blank=True)
>     payment_circle = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CIRCLE)
>     payment_option = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_OPTION)
>     amount = models.DecimalField(max_digits=8, decimal_places=2)
>     transaction_id = models.UUIDField(max_length=100, unique=True, null=True, blank=True, editable=False, default=cast_trans)
>     payment_channel = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CHANNEL_TYPE)
>     payment_date = models.DateField()
>     date_recorded = models.DateTimeField(auto_now_add=True)
>     user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
>     description = models.TextField(blank=True, null=True)
>
>     def __str__(self):
>         return self.amount
>     
>   
>     def get_absolute_url(self):
>         return reverse('backend:detail_dues', kwargs={'pk': self.id})
>
>
>
>
>
>
> --
>
> 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 [hidden email].
>
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com.
You're trying to shorten the UUID to 12 chars, that's not allowed

... simply change:

'pass_trans = str(trans_str[:12])'

to

pass_trans = str(trans_str)'

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ef7caf31-a641-43ab-bdd1-d92fc1feab5d%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: not a valid UUID.

Benedict Uwazie
Thanks for your response I just found out u can't shorten UUID but I needed 12 digits
what I now did was to import  the code below
from random import randint
my_rand = randint(100000000000, 999999999999)
transaction_id = models.CharField(max_length=30, unique=True, null=True, blank=True, editable=False, default=my_rand)

Thanks
On Sunday, 3 May 2020 11:35:30 UTC+1, Nomeh Uchenna Gabriel wrote:
On Sunday, May 3, 2020 at 9:10:28 AM UTC+1, Benedict Uwazie wrote:

> Still facing the same issue
>
> On Sunday, 3 May 2020 03:27:46 UTC+1, Motaz Hejaze  wrote:
> default=cast_trans
> cast_trans = int(pass_trans)
>
> UUID is string not int
>
>
> On Sun, May 3, 2020 at 4:05 AM Benedict Uwazie <[hidden email]> wrote:
>
>
>
> On Sunday, 3 May 2020 01:38:16 UTC+1, Benedict Uwazie  wrote:
>
> I added a field called transaction_id in my models.py I want that field to be used to track every transaction on my "DuesLevy" model I imported uuid to this to happen, but each time I migrate I get this error.
> How do i prevent this error from occurring each time I migrate (python manage.py migrate) File "C:\Users\Benedict\Miniconda3\envs\django3\lib\site-packages\django\db\models\fields\__init__.py", line 2344, in to_python
> params={'value': value},
> django.core.exceptions.ValidationError: ["'13615773708697' is not a valid UUID."]
>
>
> my models.py
>
>
> trans_id = uuid.uuid4()
> trans_str = <a href="http://trans_id.int" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftrans_id.int\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFLnRKPrOh9DNDAMgMz9F1T3lAG7Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftrans_id.int\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFLnRKPrOh9DNDAMgMz9F1T3lAG7Q&#39;;return true;">trans_id.int
> pass_trans = str(trans_str)[:12]
> cast_trans = int(pass_trans)
> class DuesLevy(models.Model):
>     class_of_dues = models.CharField(max_length=30, default=options.CHOOSE, choices=options.CLASS_OF_DUES, blank=True)
>     payment_circle = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CIRCLE)
>     payment_option = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_OPTION)
>     amount = models.DecimalField(max_digits=8, decimal_places=2)
>     transaction_id = models.UUIDField(max_length=100, unique=True, null=True, blank=True, editable=False, default=cast_trans)
>     payment_channel = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CHANNEL_TYPE)
>     payment_date = models.DateField()
>     date_recorded = models.DateTimeField(auto_now_add=True)
>     user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
>     description = models.TextField(blank=True, null=True)
>
>     def __str__(self):
>         return self.amount
>     
>   
>     def get_absolute_url(self):
>         return reverse('backend:detail_dues', kwargs={'pk': <a href="http://self.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fself.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGCR5B3zYr6QobAIs1Kda1VkZ0s9w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fself.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGCR5B3zYr6QobAIs1Kda1VkZ0s9w&#39;;return true;">self.id})
>
>
>
>
>
>
> --
>
> 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 [hidden email].
>
> To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com&#39;;return true;">https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com.



On Sunday, May 3, 2020 at 9:10:28 AM UTC+1, Benedict Uwazie wrote:

> Still facing the same issue
>
> On Sunday, 3 May 2020 03:27:46 UTC+1, Motaz Hejaze  wrote:
> default=cast_trans
> cast_trans = int(pass_trans)
>
> UUID is string not int
>
>
> On Sun, May 3, 2020 at 4:05 AM Benedict Uwazie <[hidden email]> wrote:
>
>
>
> On Sunday, 3 May 2020 01:38:16 UTC+1, Benedict Uwazie  wrote:
>
> I added a field called transaction_id in my models.py I want that field to be used to track every transaction on my "DuesLevy" model I imported uuid to this to happen, but each time I migrate I get this error.
> How do i prevent this error from occurring each time I migrate (python manage.py migrate) File "C:\Users\Benedict\Miniconda3\envs\django3\lib\site-packages\django\db\models\fields\__init__.py", line 2344, in to_python
> params={'value': value},
> django.core.exceptions.ValidationError: ["'13615773708697' is not a valid UUID."]
>
>
> my models.py
>
>
> trans_id = uuid.uuid4()
> trans_str = <a href="http://trans_id.int" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftrans_id.int\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFLnRKPrOh9DNDAMgMz9F1T3lAG7Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftrans_id.int\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFLnRKPrOh9DNDAMgMz9F1T3lAG7Q&#39;;return true;">trans_id.int
> pass_trans = str(trans_str)[:12]
> cast_trans = int(pass_trans)
> class DuesLevy(models.Model):
>     class_of_dues = models.CharField(max_length=30, default=options.CHOOSE, choices=options.CLASS_OF_DUES, blank=True)
>     payment_circle = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CIRCLE)
>     payment_option = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_OPTION)
>     amount = models.DecimalField(max_digits=8, decimal_places=2)
>     transaction_id = models.UUIDField(max_length=100, unique=True, null=True, blank=True, editable=False, default=cast_trans)
>     payment_channel = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CHANNEL_TYPE)
>     payment_date = models.DateField()
>     date_recorded = models.DateTimeField(auto_now_add=True)
>     user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
>     description = models.TextField(blank=True, null=True)
>
>     def __str__(self):
>         return self.amount
>     
>   
>     def get_absolute_url(self):
>         return reverse('backend:detail_dues', kwargs={'pk': <a href="http://self.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fself.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGCR5B3zYr6QobAIs1Kda1VkZ0s9w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fself.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGCR5B3zYr6QobAIs1Kda1VkZ0s9w&#39;;return true;">self.id})
>
>
>
>
>
>
> --
>
> 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 [hidden email].
>
> To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com&#39;;return true;">https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com.

You're trying to shorten the UUID to 12 chars, that's not allowed

... simply change:

'pass_trans = str(trans_str[:12])'

to

pass_trans = str(trans_str)'

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/29bdc56f-2a06-4687-9d9e-294b319c1e2e%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: not a valid UUID.

Motaz Hejaze
Great

On Sun, 3 May 2020, 4:49 pm Benedict Uwazie, <[hidden email]> wrote:
Thanks for your response I just found out u can't shorten UUID but I needed 12 digits
what I now did was to import  the code below
from random import randint
my_rand = randint(100000000000, 999999999999)
transaction_id = models.CharField(max_length=30, unique=True, null=True, blank=True, editable=False, default=my_rand)

Thanks
On Sunday, 3 May 2020 11:35:30 UTC+1, Nomeh Uchenna Gabriel wrote:
On Sunday, May 3, 2020 at 9:10:28 AM UTC+1, Benedict Uwazie wrote:

> Still facing the same issue
>
> On Sunday, 3 May 2020 03:27:46 UTC+1, Motaz Hejaze  wrote:
> default=cast_trans
> cast_trans = int(pass_trans)
>
> UUID is string not int
>
>
> On Sun, May 3, 2020 at 4:05 AM Benedict Uwazie <[hidden email]> wrote:
>
>
>
> On Sunday, 3 May 2020 01:38:16 UTC+1, Benedict Uwazie  wrote:
>
> I added a field called transaction_id in my models.py I want that field to be used to track every transaction on my "DuesLevy" model I imported uuid to this to happen, but each time I migrate I get this error.
> How do i prevent this error from occurring each time I migrate (python manage.py migrate) File "C:\Users\Benedict\Miniconda3\envs\django3\lib\site-packages\django\db\models\fields\__init__.py", line 2344, in to_python
> params={'value': value},
> django.core.exceptions.ValidationError: ["'13615773708697' is not a valid UUID."]
>
>
> my models.py
>
>
> trans_id = uuid.uuid4()
> trans_str = trans_id.int
> pass_trans = str(trans_str)[:12]
> cast_trans = int(pass_trans)
> class DuesLevy(models.Model):
>     class_of_dues = models.CharField(max_length=30, default=options.CHOOSE, choices=options.CLASS_OF_DUES, blank=True)
>     payment_circle = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CIRCLE)
>     payment_option = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_OPTION)
>     amount = models.DecimalField(max_digits=8, decimal_places=2)
>     transaction_id = models.UUIDField(max_length=100, unique=True, null=True, blank=True, editable=False, default=cast_trans)
>     payment_channel = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CHANNEL_TYPE)
>     payment_date = models.DateField()
>     date_recorded = models.DateTimeField(auto_now_add=True)
>     user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
>     description = models.TextField(blank=True, null=True)
>
>     def __str__(self):
>         return self.amount
>     
>   
>     def get_absolute_url(self):
>         return reverse('backend:detail_dues', kwargs={'pk': self.id})
>
>
>
>
>
>
> --
>
> 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 [hidden email].
>
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com.



On Sunday, May 3, 2020 at 9:10:28 AM UTC+1, Benedict Uwazie wrote:

> Still facing the same issue
>
> On Sunday, 3 May 2020 03:27:46 UTC+1, Motaz Hejaze  wrote:
> default=cast_trans
> cast_trans = int(pass_trans)
>
> UUID is string not int
>
>
> On Sun, May 3, 2020 at 4:05 AM Benedict Uwazie <[hidden email]> wrote:
>
>
>
> On Sunday, 3 May 2020 01:38:16 UTC+1, Benedict Uwazie  wrote:
>
> I added a field called transaction_id in my models.py I want that field to be used to track every transaction on my "DuesLevy" model I imported uuid to this to happen, but each time I migrate I get this error.
> How do i prevent this error from occurring each time I migrate (python manage.py migrate) File "C:\Users\Benedict\Miniconda3\envs\django3\lib\site-packages\django\db\models\fields\__init__.py", line 2344, in to_python
> params={'value': value},
> django.core.exceptions.ValidationError: ["'13615773708697' is not a valid UUID."]
>
>
> my models.py
>
>
> trans_id = uuid.uuid4()
> trans_str = trans_id.int
> pass_trans = str(trans_str)[:12]
> cast_trans = int(pass_trans)
> class DuesLevy(models.Model):
>     class_of_dues = models.CharField(max_length=30, default=options.CHOOSE, choices=options.CLASS_OF_DUES, blank=True)
>     payment_circle = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CIRCLE)
>     payment_option = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_OPTION)
>     amount = models.DecimalField(max_digits=8, decimal_places=2)
>     transaction_id = models.UUIDField(max_length=100, unique=True, null=True, blank=True, editable=False, default=cast_trans)
>     payment_channel = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CHANNEL_TYPE)
>     payment_date = models.DateField()
>     date_recorded = models.DateTimeField(auto_now_add=True)
>     user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
>     description = models.TextField(blank=True, null=True)
>
>     def __str__(self):
>         return self.amount
>     
>   
>     def get_absolute_url(self):
>         return reverse('backend:detail_dues', kwargs={'pk': self.id})
>
>
>
>
>
>
> --
>
> 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 [hidden email].
>
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4a1d77cc-d1b8-4bd4-84cd-cd78e6d2eb76%40googlegroups.com.

You're trying to shorten the UUID to 12 chars, that's not allowed

... simply change:

'pass_trans = str(trans_str[:12])'

to

pass_trans = str(trans_str)'

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/29bdc56f-2a06-4687-9d9e-294b319c1e2e%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHV4E-dtnyCR%3D5CqwB2bZK6W75pU_HHXppLZ4BDhRJRfL--jWQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: not a valid UUID.

Nomeh Uchenna Gabriel
In reply to this post by Benedict Uwazie
That looks good to you but is definitely a dangerous approach if the "12 digits" should be unique for each QuerySet since "random.random" can return dublicate numbers when called multiple times.

... I suggest you make a function for that or novicely adds the item's 'pk' to the random number making sure that it's still not more than 12 digits

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/71c45bae-8cb2-433d-ae27-2d4275c7182c%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: not a valid UUID.

Nomeh Uchenna Gabriel
[CONTINUED]
I just saw "unique=true" on that field

... you may not face the problems of using "random" just yet but must face it at some "random time in the future" - once you see something like this:

   >>>: IntegrityError

... then shall you remember my reply.

The best option is to use a well guided function - I could even help you with that if you don't know much about it on my leisure.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a55e8d2f-1511-4678-9c9a-1b40a93a8025%40googlegroups.com.