1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Flask SQL model missing one positional argument

Discussão em 'Python' iniciado por Stack, Setembro 16, 2025.

  1. Stack

    Stack Membro Participativo

    from flask import (Flask, render_template)
    from flask_sqlalchemy import SQLAlchemy

    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://user:password@localhost/database'
    db = SQLAlchemy(app)

    class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    nickname = db.Column(db.String(80), unique=True)

    def __init__(self, id, nickname):
    self.id = id
    self.nickname = nickname

    admin = User('admin')


    This code throws TypeError: __init__() missing 1 required positional argument: 'nickname', so it seems like it expects me to manually set the id, though i probably shouldn't do it? I also tried executing User(nickname='admin'), but it doesn't seem to work. Thanks for the help

    Continue reading...

Compartilhe esta Página