I am doing one lesson and repeat everything, but I cant create a database. There 2 problems:
psycopg2.OperationalError
peewee.OperationalError
This is my code:
import csv
from peewee import *
db = PostgresqlDatabase(database='test', user='postgres', password='123', host='localhost')
class Coin(Model):
name = CharField()
url = TextField()
price = CharField()
class Meta:
database = db
def main():
db.connect()
db.create_tables([Coin])
with open('cmc.csv') as f:
order = ['name', 'url', 'price']
reader = csv.DictReader(f, fieldnames=order)
coins = list(reader)
with db.atomic():
for index in range(0, len(coins), 100):
Coin.insert_many(coins[index:index+100]).execute()
if __name__ == '__main__':
main()
source https://stackoverflow.com/questions/74082638/i-cant-create-database-with-python-in-postgres
Comments
Post a Comment