简体   繁体   中英

Insert Faker data in MySQL database with Python 3.9.5

I have very simple table: customers (id int auto_increment, name varchar(255), address varchar(255).

Want to insert fake data using npm faker with python.

Started Python yesterday and I`m lost. Help plz.

Tried many queries but does not work.

 for i in range (10):

   name = fake.name()

  address =fake.address()

  mycursor.executemany("INSERT INTO customers (name, address)\ VALUES ({},{})"

  db.commit()

for i in range(10):

name=fake.name()

address=fake.street_address()

cur.execute('insert into customers(name,address) VALUES (%s,%s)', (name, address));

db.commit()

print('FINALLY')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM