hello so I've been writing this script to pre-populate my Django database but when I stopped writing it I got a weird error: My Script:
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'first_project.settings')
import django
django.setup()
## FAKE POPULATION SCRIPT:
import random
from first_app.models import AccessRecord,Webpage,Topic
from faker import Faker
# Creating a fake generator:
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()
return t
def populate(N = 5):
for entry in range(N):
# GET THE TOPIC FOR THE ENTRY:
top = add_topic()
# Create the fake data for that entry:
fake_url = fakegen.url()
fake_date = fakegen.date()
fake_name = fakegen.company()
# Create the new webpage entry:
webpg = Webpage.objects.get_or_create(topic = top, url = fake_url, name = fake_name)[0]
# Create a fake access record for that webpage
acc_rec = AccessRecord.get_or_create(name = webpg, date = fake_date)[0]
if __name__ == '__main__':
print("Populating Script!")
populate(20)
print("Populating Complete!")
The error I get:
python populate_first_app.py
Traceback (most recent call last):
File "populate_first_app.py", line 11, in <module>
from faker import Faker
File "E:\Python\Projects\Python And Django FullStack\Django\first_project\faker.py", line 1, in <module>
from faker import Faker
ImportError: cannot import name 'Faker' from 'faker'
I've never seen the error like this I am using this script under the influence of a virtual environment which I already installed all the packages I already checked a few things like uninstalling and installing the 'faker' library again but it didn't work and I still get the error.