1

Background info: I am quite beginner with django, better equipped with python and quite beginner in mysql (and thus mariaDB) as well. I work in Windows 7 environment with the following versions:

  • django 1.9.1
  • mariaDB 10.0.20
  • Python 3.4.4
  • mysql-connector\Python 2.1.3 for Python 3.4

Goal: I am trying to build mariaDB database and web based user interface for it with django. I have built the database beforehand in mysql and am now trying to create the django project using this database as legacy database.

Problem: I have retrieved the models to my django project as follows:

python manage.py inspectdb > models.py

and it worked fine. Checked the models.py, as well, and they seemed as they should.

Now, if I try to migrate to create the tables based on django to my legacy db as follows:

python manage.py migrate

I keep getting plenty of nested errors last one being:

django.db.migrations.exceptions.MigrationsSchemaMissing: Unable to create the django_migrations table (Table 'mydb'.'django_migrations' already exists. Please DISCARD the tablespace before IMPORT.)

I figured the table was left in my database folder from previous attempt, but removing it does not help. Even if I check from the database command prompt that the only tables left are native to my database, this same error message pops up still. At some point I wondered if there is some issue with the connector I am using as it is not the recommended one (mysqlclient).

Somewhere, I found that the migration would not even be required. This would obviously save me, but I have no idea, if that is a solution I can go for. Ideally the database would be managed later online and users with admin accounts could add entries there. Otherwise, however the database should be just returning the data.

EDIT: Fixed the error message the python manage.py inspectdb > models.py line

EDIT 29.1. Running the migration as:

python manage.py migrate --fake

results in the same error.

The issue persists even after removing the django project and starting it fresh.

EDIT v2 29.1. There is only one of the required table files for the django_migrations table within the database folder. There should be django_migrations.ibd AND django_migrations.frm. However, after running the migration, there is only one file: django_migrations.ibd.

There was something similar going on here, with different file mysqldump problems with restore error: 'Please DISCARD the tablespace before IMPORT'. It is well explained in the chosen answer.

I think this is related to my issue, but cannot figure out what could help and what to do with this.

EDIT v3 29.1. And finally I noticed the file giving the django error. It is django's migration recorder at C:\Python34\lib\site-packages\django\db\migrations\recorder.py on line 59.

def ensure_schema(self):
    """
    Ensures the table exists and has the correct schema.
    """
    # If the table's there, that's fine - we've never changed its schema
    # in the codebase.
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
        return
    # Make the table
    try:
        with self.connection.schema_editor() as editor:
            editor.create_model(self.Migration)
    except DatabaseError as exc:
        raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)

Where the last line raising the error is the line 59. Funnily, the function should work, if the table exists. Only thing I can come up with (as in my previous edit), is that indeed for some reason the frm-file is not created during the migration process.

Why that happens is way beyond me.

Community
  • 1
  • 1
scinaya
  • 61
  • 1
  • 6
  • I have decided to try to flow without migrations. Updating the rows and accessing data in database seems to work fine, so this should be sufficient for my project. If anyone, however, figures out why this error keeps happening, I'd be interested to know. – scinaya Feb 02 '16 at 13:46

0 Answers0