'populate Django database my code with Faker library, when I was compiling it did not showing any error, but not populate fake data in admin page
Solution 1:[1]
Note
I don't understand why are you using faker but if you want to populate your database with random data then in
fake_data.py
# Import your libraries here
import random
# define your here
def main():
# Call populate
print("Populating random data begins ...")
populate(20)
print("Populating random data ends ...")
# random tasks
todos = ["foo", "bar", "bazz"]
def add_todo():
# Create and save records in database
q = TODO.objects.create(name=random.choice(todos))
return q
def populate(N=5):
for counter in range(N):
entry = add_todo()
# call your main
if __name__ == "__main__":
main()
- Note that if you don't use
qandentryelse where in your code, then remove both of them.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | shah sawood |



