Skip to content

Instantly share code, notes, and snippets.

@zyryc
Created December 25, 2020 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zyryc/3150ca2ad8de735252753746ee0dbef6 to your computer and use it in GitHub Desktop.
Save zyryc/3150ca2ad8de735252753746ee0dbef6 to your computer and use it in GitHub Desktop.
generate fake data for your database
import sqlite3
from faker import Faker
from random import randrange
fake = Faker()
conn = sqlite3.connect('users.sqlite3')
cursor = conn.cursor()
# if updating table, comment the create part
cursor.execute('''
CREATE TABLE users ( p_ID INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(200) NOT NULL, dob date NOT NULL, address text NOT NULL, about text NOT NULL)
''')
for x in range(1,100):
name = fake.name()
details = fake.sentence()
adress = fake.address()
dob = fake.date()
params = (name, adress, dob, details)
cursor.execute('''
INSERT INTO users( p_ID, name, address, dob,about)
VALUES ( NULL,?,?,?,?)
''', params)
cursor.execute('''
SELECT *
FROM users
''')
all_rows = cursor.fetchall()
for row in all_rows:
print(row)
conn.commit()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment