0

In his application he created alternately three models and the connections between them:

class Operation(db.Model):
    __tablename__ = "operation"
    id = db.Column(db.Integer, primary_key=True)    
    date_operation = db.Column(db.DateTime)    
    status_id = db.Column(db.Integer, db.ForeignKey('status.id'))
    status = db.Column(db.String(60))    
    contragent_id = db.Column(db.Integer, db.ForeignKey('contragent.id'))
    contragent = db.Column(db.String(240))

    def __repr__(self):
        return '<Operation {}>'.format(self.code)


class Contragent(db.Model):
    __tablename__ = "contragent"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(360))
    code = db.Column(db.Integer, index=True)
    adress = db.Column(db.String(480))
    inn = db.Column(db.Integer)
    operations = db.relationship('Operation',uselist=False, backref='operat')  

    def __repr__(self):
        return '<Contragent {}>'.format(self.name)


class Status(db.Model):
    __tablename__ = "status"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(360))    
    timestamp = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    operations = db.relationship('Operation', uselist=False, backref='operat')

    def __repr__(self):
        return '<Status {}>'.format(self.name)

After creating the Status model with operations = db.relationship ('Operation', uselist = False, backref = 'operat') the database broke down. When attempting to delete the Status model before commented out the class Status, an error occurs:

(venv) C:\Users\User\testapp>flask db migrate -m "status table"
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Traceback (most recent call last):
    ....
        raise exc.NoSuchTableError(table.name)
sqlalchemy.exc.NoSuchTableError: status

What causes the error and how can I delete the Status table to create the correct link again?

Ambasador
  • 365
  • 3
  • 14

1 Answers1

0

you have used status.id as foreign key in Operation table.Remove all references to Status table and then try to delete the table. Maybe that'll solve the problem for you.

  • Did not help.When I removed from the model the indication of the primary key from Operation and tried to apply the changes to the same error: `sqlalchemy.exc.NoSuchTableError: status` – Ambasador Jul 05 '19 at 11:31