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
Flask not generating any migration #220
Comments
What are the contents of the file |
These are the contents |
Did you import |
Just did, made the following changes in the app's
Also the made the following changes in the models
It didn't work at first. I commented out the following lines in
and run the migrations and it worked, I then uncommented the lines again and it worked. It's quite puzzling really, is there some kind of cache that happens, that we should be aware of? This problems tend to appear for a new dev as soon as they've cloned the project ad are setting up. |
Not sure, but I think I was right with my guess that your models weren't being imported when you run |
Okay. I think I need to do a bit more research on the occasional odd behaviour. Just to clarify one thing though, models should be imported after the instantiation of db and migrate, right? |
Your model classes inherit from Note that if you use a linter, it may flag the models as being unused imports. This is fine, importing the models is necessary anyway, as Alembic and SQLAlchemy use introspection to find the models among all the imported symbols. If the models are not imported, then Alembic will think you have no models in your database schema, which is what happened to you. |
Thanks for the clarification. |
Hello @miguelgrinberg I 'm understand , how i can make in factory app? |
@johndiego see https://github.com/miguelgrinberg/flasky for an example. |
Thanks @michaelbukachi !! |
@miguelgrinberg I'm try create new project , but don't work the flask migrate!
I used two commands |
@johndiego The "target is not up to date" error means that you have migrations that haven't been applied to the database. You need to look in your migrations/versions directory to see if you have any extra migrations that should not be there, or else you may need to run "flask db upgrade" to apply any migrations that are part of your project. |
@michaelbukachi , i had same trouble and i found solve for me in alembic env.py file - pay attention for this lines: |
@4vadim4 I was able to fix the issue. It seems my models weren't being imported properly. |
Thanks..!! This worked for me too..!! Now, flask db migrate is working fine and generating migrations.. |
@5hraddha @michaelbukachi all you are doing is explicitly import your models in the Alembic config file. This would not be necessary if the models were imported somewhere in your app, which was my diagnosis when this issue started:
Given that you guys are now functional I'm going to close this issue. Please reopen if there are still problems. |
Hi Miguel, I am using flask-migrate library for migration. I have created models in models package not in my manage.py file. When I tried to migrate the model using
is my output. It means it is not detecting the models which I define in model folder. This is my manage.py content _from flask_migrate import Migrate, MigrateCommand from app import app, db migrate = Migrate(app, db) if name == 'main': This is my model file content _from manage import db class Employee(db.Model):
Please help me. |
Hi there, I am unable to figure out why my migration files not generating for flask multidb. Since the last two days I have tried, and gone through all the comments, but unable to resolve. Can you help me with this, please!!
this is the
this is my
this is
this is
Now while running
Please help me to debug my code. If I am missing something, please tell me or my structure alteration is doing any problem, please let me know. I would be highly appreciated to get any suggestions. Thanks, |
"No changes in schema detected" means that your models and the database have the same structure. Two possible reasons:
The 2nd one has some variants. I've seen people create two database objects, and the models are imported into one, but Flask-Migrate is configured with the other. I thought I'd mention this, seeing that you are using a very strange mix of Flask-SQLAlchemy with regular SQLAlchemy. |
$ python -m manage db migrate
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL. When I changed something in my models, migrate didn't work. |
need your help, I have this problem, I'm trying to make a migration, and get this error:
my repo is here: my app-run is run.py: from scr import app
if __name__ == '__main__':
app.run() my app-init is inside of scr: from flask import Flask
from flask_migrate import Migrate
from config import Config
from .routes import global_scope
from flask_sqlalchemy import SQLAlchemy
from .models import db
# initialization app
app = Flask(__name__, static_folder=Config.STATIC_FOLDER, template_folder=Config.TEMPLATE_FOLDER)
app.config.from_object(Config)
# instances
SQLAlchemy(app)
migrate = Migrate(app, db)
# create tables
with app.app_context():
db.create_all()
# blueprints
app.register_blueprint(global_scope, url_prefix='/') my import "db": from flask_sqlalchemy import SQLAlchemy
# instance to use SQLAlchemy
db = SQLAlchemy() my models is in ModelUser.py from .db import db
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)
firstName = db.Column(db.String(25), nullable=False)
lastName = db.Column(db.String(25), nullable=False)
email = db.Column(db.String(80), nullable=False)
def __init__(self, name, firstName, lastName, email):
self.name = name
self.firstName = firstName
self.lastName = lastName
self.email = email
def __repr__(self):
return f'{self.name}'
class Face(db.Model):
id = db.Column(db.Integer, primary_key=True)
vectorEyes = db.Column(db.Integer, nullable=False)
vectorEars = db.Column(db.Integer, nullable=False)
vectorLips = db.Column(db.Integer, nullable=False)
pic = db.Column(db.BLOB)
user = db.Column(db.String(80), nullable=False)
def __init__(self, vectorEyes, vectorEars, vectorLips, user):
self.vectorEyes = vectorEyes
self.vectorEars = vectorEars
self.vectorLips = vectorLips
self.user = user
def face(self, pic, user):
self.user = user
self.pic = pic
def __repr__(self):
return f'{self.pic, self.user}'
class Tickets(db.Model):
id = db.Column(db.Integer, primary_key=True)
fullNameUser = db.Column(db.String(80), nullable=False)
ticket = db.Column(db.Integer, nullable=False)
def __init__(self, fullNameUser, ticket):
self.fullnameUser = fullNameUser
self.ticket = ticket plss helpme, I've been trying for three days |
@emmanuel-rosillo I think it would be better if you start from a more "traditional" structure, and then start making changes if you need to. This is a strange way to initialize your app, where you have |
I just solved this problem, just export in this mode:
in my case
pd: in my case, enter the folder scr who containing my folder_models to create folder_migrations aside. folder models: run the command in path: my command complete: (venv) elalocador@alocadora:~/Desktop/facial_comparate/Register/application/scr$ export FLASK_APP=/home/elalocador/Desktop/facial_comparate/Register/application/run.py
(venv) elalocador@alocadora:~/Desktop/facial_comparate/Register/application/scr$ flask db init thak you so much, @miguelgrinberg , for your help |
Hello there,
I'm in a huge pickle. Flask-Migrate is not generating any migrations. I keep getting the following:
My directory structure is as follows:
Here's my main
__init__.py
file:My model's
__init__.py
file is as follows:My
database.py
file is as follows:They are later initialized in
factory.py
below:I can't get it to work with sqlite or postgres. I'm not sure if my directory structure is the problem or I'm missing a step. Some guidance would be highly appreciated.
Thanks.
The text was updated successfully, but these errors were encountered: