Django Test.py django.db.utils.IntegrityError: UNIQUE constraint failed: books_book.id
когда я запускаю python manage.py tests
Я получаю эту ошибку как django.db.utils.IntegrityError: UNIQUE constraint failed: books_book.id
это приводит к неудаче большинства других тестов
Вот полный tests.py
файл:
class BookViewTests(TestCase):
self.user=get_user_model().objects.create_user(
username='test',
email='test@gmail.com',
city='city',
state='state',
password='secret',
id_2 ='96540845',
work = 'Wipro'
)
self.book =Book.objects.create(
title='How to Win Friends and Influence People',
author='Dale Carnegie',
genre ='Self-help',
owner =self.user,
id ='75777553',
is_approved=False,
available=False
)
#book detail view
def test_book_detail_view(self):
self.client.login(username='test',password='secret')
resp =self.client.get(reverse('book_detail',kwargs={'book_id':75777553}))
self.assertEqual(resp.status_code,200)
self.assertTemplateUsed(resp,'book_detail.html')
Это моя модель
My model
:
class Book(models.Model):
id=models.SlugField(max_length=8,primary_key=True)
genre_choices=[(i,i) for i in ['Biography','Business','Children','Classic','Comedy','Fantasy','History','Horror','Mystery','Mythology','Poetry','Religion','Romance','SciFi','Self-Help','Spirituality','Thriller','Non-Fiction','Fiction','Others']]
title =models.CharField(max_length =255)
author =models.CharField(max_length =255,validators=[alphabet_validate])
genre =models.CharField(max_length=100,choices=genre_choices)
available =models.BooleanField(default =True)
slug = models.SlugField(verbose_name='Slug', null=True,blank=True,max_length = 200)
Как решить эту проблему? Заранее спасибо.