AttributeError: 'SqliteDatabase' object has no attribute 'Infraction'

Skip to first unread message


Apr 20, 2021, 9:13:56 PM4/20/21
to peewee-orm
Hey, I was casually trying to do some data creation with peewee, but I got this error.

AttributeError: 'SqliteDatabase' object has no attribute 'Infraction'

Under core/ I have:

import logging
import os
from peewee import *
from discord.enums import ExpireBehavior
from playhouse.shortcuts import model_to_dict, dict_to_model 
from playhouse.sqlite_ext import RowIDField
from datetime import datetime
from playhouse.shortcuts import ReconnectMixin
from flask import Flask
from peewee import *

db = SqliteDatabase("data.db", pragmas={'foreign_keys': 1})
logger = logging.getLogger(__name__)

def iter_table(model_dict):
  for key in model_dict:
    if not db.table_exists(key):
     logger.debug(f"Created table '{key}'")

class BaseModel(Model):
  class Meta:
    database = db

class Infraction(BaseModel):
"""Stores our warnings."""
  id = AutoField()
  userID = TextField()
  reason = TextField()
  typeAction = TextField()
  MuteTimeRelease = TextField(default = None)
  ActiveMute = TextField(default=False)

app = Flask(__name__)

def _db_connect():

def _db_close(exc):
  if not db.is_closed():

tables = {"infraction": Infraction}

Then under core/ I have:

from datetime import datetime, timedelta
import discord
from core import database

async def addEntry(self, ctx, target, reason, typeAction, MuteRelease = None, ActiveWarn = False):
  warn: database.db.Infraction = database.db.Infraction.create(userID = target, reason =     reason, typeAction = typeAction, MuteTimeRelease = MuteRelease, ActiveWarn = ActiveWarn)


I've tried renaming the SQLite object but I had no luck getting it to recognize that class.

Charles Leifer

Apr 23, 2021, 11:25:42 AM4/23/21
It does seem like you are running into some naming conflict with your modules, rather than this being a peewee bug. I'd suggest stepping back and simplifying your modules and seeing if you can figure out where you've made a mistake...

For what it's worth it looks like you're trying to access "Infraction" as if it were an attribute of the peewee database object, which makes no sense.




database.Infraction (module . ModelName)

You received this message because you are subscribed to the Google Groups "peewee-orm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages