sdispater/flask-orator

[AttributeError] __exit__ when running migrate:reset

Closed this issue · 3 comments

I'm running Ubuntu 16.04 with virtualenv & python 2.7.

When running migrate reset command on shell, it always return [AttributeError] __exit__. But it didnt happen for migrate command.

orator.py :

from orator import DatabaseManager, Schema
databases = {
    'mysql': {
        'driver': 'mysql',
        'host': 'localhost',
        'database': 'my_database',
        'user': 'my_user',
        'password': 'my_password',
        'prefix': ''
    }
}
db = DatabaseManager(databases)

my migration file 2016_11_23_100336_create_customer_table.py :

from orator.migrations import Migration

class CreateCustomerTable(Migration):

    def up(self):
        """
        Run the migrations.
        """
        with self.schema.create('customer') as table:
            table.increments('cust_id')
            table.string('email', 100).unique()
            table.string('username', 100).unique()
            table.string('mobileno', 15).unique()
            table.string('password', 254)
            table.string('fname', 50).nullable()
            table.string('lname', 50).nullable()
            table.string('image_path', 254).nullable()
            table.boolean('status')
            table.nullable_timestamps()
            pass

    def down(self):
        """
        Revert the migrations.
        """
        with self.schema.drop_if_exists('customer') as table:
            pass

That's odd. Which version of cleo do you have?

Oh! Disregard my previous comment. self.schema.drop_if_exists('customer') is not a context manager so you can't use it like you do in down(). It should be:

def down(self):
    """
    Revert the migrations.
    """
    self.schema.drop_if_exists('customer')

Thx, its worked

Its my first time with Python.
Noob mistake.