Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't import models module #63

Open
JosXa opened this issue Dec 7, 2017 · 4 comments
Open

Can't import models module #63

JosXa opened this issue Dec 7, 2017 · 4 comments

Comments

@JosXa
Copy link

JosXa commented Dec 7, 2017

Hi there,

first of all thank you so much for taking the time and publishing this library, appreciate it a lot since peewee doesn't come with automatic migrations included.

I'm trying to use the cli to migrate my model, but load_models raises an Exception, saying that it can't import the models module (the one at the --auto path).

This is the failing command:
$ pw_migrate create --auto ~/myproject/model/ --database "postgres://zudibytvipthsa:c8c2d7f0blabla" --directory ~/myproject/model/ mymigration

Could it be that peewee_migrate doesn't resolve the database connection URL with playhouse.db_url.connect but expects something else instead? This isn't really clear from the help text.

My model module is structured as follows:

model/
    basemodel.py  <-- containing:
    class BaseModel(Model):
        class Meta:
             database = db

    .. more modules that inherit from BaseModel

I would appreciate getting some hints as to what might be causing this :)

@Thorbijoern
Copy link

first you could take a look at #16 because of your BaseModel.
i don't really know postgres, but the url should work like explained in the playhouse docs.

i think the command fails because it can't import your module:
pw_migrate create --auto=model.basemodel --database="postgres://zudibytvipthsa:c8c2d7f0blabla" --directory="~/myproject/model/" mymigration
this could work. i think you have to make sure that you can import the models with python like a normal module from your working directory.

@metallerok
Copy link

You can try adding the following lines to the beginning of the migration file:

import os
import sys
sys.path.append(os.path.dirname("__file__"))

@JosXa
Copy link
Author

JosXa commented Jan 21, 2021

Whew, answers coming in 4 years later 😁 Appreciate it, but I've moved on

@CollinLeishman
Copy link

Whew, answers coming in 4 years later 😁 Appreciate it, but I've moved on

They're not just for you 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants