database-migration

Fixing a typo in models.py and migration for django python project

Fixing a typo in models.py and migration for django python project Question: I’m working on my first django project following along with a youtube tutorial. In models.py while following along I made a typo… crated_at = models.DateTimeField(default=datetime.now) "crated_at" should be "created_at". The typo is reflected in my migrations. I tried changing both models.py and the …

Total answers: 2

Database migrations in Flask without SQLAlchemy

Database migrations in Flask without SQLAlchemy Question: Is there any library or tool to perform database migrations in python without SQLAlchemy? I am using a PostgreSQL database and the queries are raw SQL. I use psycopg2 for the database connection. Asked By: Yosry || Source Answers: In short, “yes.” There are numerous possibilities. The one …

Total answers: 2

django.db.migrations.exceptions.InconsistentMigrationHistory

django.db.migrations.exceptions.InconsistentMigrationHistory Question: When I run python manage.py migrate on my Django project, I get the following error: Traceback (most recent call last): File “manage.py”, line 22, in <module> execute_from_command_line(sys.argv) File “/home/hari/project/env/local/lib/python2.7/site- packages/django/core/management/__init__.py”, line 363, in execute_from_command_line utility.execute() File “/home/hari/project/env/local/lib/python2.7/site-packages/django/core/management/__init__.py”, line 355, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File “/home/hari/project/env/local/lib/python2.7/site-packages/django/core/management/base.py”, line 283, in run_from_argv self.execute(*args, **cmd_options) File “/home/hari/project/env/local/lib/python2.7/site-packages/django/core/management/base.py”, line …

Total answers: 35

How does django know which migrations have been run?

How does django know which migrations have been run? Question: How does django know whether a migration has been applied yet? It usually gets it right, but when it doesn’t I don’t ever know where to start troubleshooting. Asked By: BostonJohn || Source Answers: Django writes a record into the table django_migrations consisting of some …

Total answers: 5

sqlalchemy : executing raw sql with parameter bindings

sqlalchemy : executing raw sql with parameter bindings Question: I’m trying to run this simple raw sql statement with parameters with SQLALchemy (within an alembic script) : from alembic import op t = {“code”: “123”, “description”: “one two three”} op.execute(“insert into field_tags (id, field_id, code, description) “+ “values (1,’zasz’, :code ,:description’)”, t) And I get …

Total answers: 1