I keep getting an IntegrityError when i try to use Faker to populate my script

I've tried to delete the migrations folder and then redo the makemigrations process but i keep getting the same IntegrityError and it is probably coming from the migrations code itself but i don't understand it as the creation of the code was automatic by Django. The code below is my population script.

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "first_project.settings")

import django
django.setup()

import random
from first_app.models import AccessRecord, Webpage, Topic
from faker import Faker




fakegen = Faker()
topics = ['Search', 'Social', 'Marketplace', 'News', 'Games']


def add_topic():
    t = Topic.objects.get_or_create(top_name=random.choice(topics))[0]
    t.save()


def populate(N=5):
    for entry in range(N):
        top = add_topic()

        fake_url = fakegen.url()
        fake_date = fakegen.date()
        fake_name = fakegen.company()

        webpg = Webpage.objects.get_or_create(topic=top, url=fake_url, name=fake_name)[0]

        acc_rec = AccessRecord.objects.get_or_create(name=webpg, date=fake-date)[0]


if __name__ == '__main__':
    print('populating script')
    populate(20)
    print('populating complete')
Back to Top