Created
December 25, 2020 08:25
-
-
Save zyryc/3150ca2ad8de735252753746ee0dbef6 to your computer and use it in GitHub Desktop.
generate fake data for your database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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