django 1.8 , makemigrations throwing errors

1,192 views
Skip to first unread message

John Emmatty

unread,
Sep 11, 2015, 3:42:03 PM9/11/15
to Django users
I ran makemigrations against my legacy, MySQL database and it created models.py file for me, I copied the file to my applications package directory and ran makemigrations again after adding a table to extend the default users table. Now makemigrations is throwing following errors . I created a fresh django project which had no reference to older versions.

SystemCheckError: System check identified some issues:

    ERRORS:
    djangogettrix.AuthGroupPermissions: (models.E012) 'unique_together' refers to the non-existent field 'group_id'.
    djangogettrix.AuthGroupPermissions: (models.E012) 'unique_together' refers to the non-existent field 'permission_id'.
    djangogettrix.AuthPermission: (models.E012) 'unique_together' refers to the non-existent field 'content_type_id'.
    djangogettrix.AuthUserGroups: (models.E012) 'unique_together' refers to the non-existent field 'group_id'.
    djangogettrix.AuthUserGroups: (models.E012) 'unique_together' refers to the non-existent field 'user_id'.
    djangogettrix.AuthUserUserPermissions: (models.E012) 'unique_together' refers to the non-existent field 'permission_id'.
    djangogettrix.AuthUserUserPermissions: (models.E012) 'unique_together' refers to the non-existent field 'user_id'.
    djangogettrix.RolesUsers: (models.E012) 'unique_together' refers to the non-existent field 'role_id'.
    djangogettrix.RolesUsers: (models.E012) 'unique_together' refers to the non-existent field 'user_id'.

Kindly help me by throwing some light on this.

James Schneider

unread,
Sep 13, 2015, 5:15:24 AM9/13/15
to django...@googlegroups.com
On Fri, Sep 11, 2015 at 10:37 AM, John Emmatty <johne...@gmail.com> wrote:
I ran makemigrations against my legacy, MySQL database and it created models.py file for me, I copied the file to my applications package directory and ran makemigrations again after adding a table to extend the default users table. Now makemigrations is throwing following errors . I created a fresh django project which had no reference to older versions.


Are you sure that 'makemigrations' created a models.py file for you? It should only create migration files, something like 0003_auto.py?

Did you apply the original migration before adding the new table and new migration? I'm wondering if makemigrations is expecting/assuming that your DB schema is up to date? Sounds like it wasn't. A quick look through the migration docs didn't reveal an easy answer.

I'm no migration expert, but I would make sure the DB schema matched the latest migration before making further changes/migrations. 

 
SystemCheckError: System check identified some issues:

    ERRORS:
    djangogettrix.AuthGroupPermissions: (models.E012) 'unique_together' refers to the non-existent field 'group_id'.
    djangogettrix.AuthGroupPermissions: (models.E012) 'unique_together' refers to the non-existent field 'permission_id'.
    djangogettrix.AuthPermission: (models.E012) 'unique_together' refers to the non-existent field 'content_type_id'.
    djangogettrix.AuthUserGroups: (models.E012) 'unique_together' refers to the non-existent field 'group_id'.
    djangogettrix.AuthUserGroups: (models.E012) 'unique_together' refers to the non-existent field 'user_id'.
    djangogettrix.AuthUserUserPermissions: (models.E012) 'unique_together' refers to the non-existent field 'permission_id'.
    djangogettrix.AuthUserUserPermissions: (models.E012) 'unique_together' refers to the non-existent field 'user_id'.
    djangogettrix.RolesUsers: (models.E012) 'unique_together' refers to the non-existent field 'role_id'.
    djangogettrix.RolesUsers: (models.E012) 'unique_together' refers to the non-existent field 'user_id'.


Sounds like tables are missing that makemigrations is expecting to be present, which would lend a small amount of credibility to my theory above.

Again, I don't have nearly enough experience with complicated migration scenario's to give you a definitive answer, though.

-James

ernando

unread,
Sep 14, 2015, 1:51:58 PM9/14/15
to Django users
Hey John,

Agree with James. makemigrations command doesn't create models.py file - it's on your plate. But after creating models.py file and filling it with your models - you have to create migration file with makemigrations command and run migrate one to create all required tables, fk, etc.

- Dmitry

Christoph Knapp

unread,
Oct 21, 2015, 7:11:40 AM10/21/15
to Django users
Hi,
I have the same problem.

The models.py file was created by

python manage.py inspectdb > models.py

I just copied it over into my app and modified it. My output is

readDatabase.AuthGroupPermissions: (models.E012) 'unique_together' refers to the non-existent field 'group_id'.
readDatabase.AuthGroupPermissions: (models.E012) 'unique_together' refers to the non-existent field 'permission_id'.
readDatabase.AuthPermission: (models.E012) 'unique_together' refers to the non-existent field 'content_type_id'.
readDatabase.AuthUserGroups: (models.E012) 'unique_together' refers to the non-existent field 'group_id'.
readDatabase.AuthUserGroups: (models.E012) 'unique_together' refers to the non-existent field 'user_id'.
readDatabase.AuthUserUserPermissions: (models.E012) 'unique_together' refers to the non-existent field 'permission_id'.
readDatabase.AuthUserUserPermissions: (models.E012) 'unique_together' refers to the non-existent field 'user_id'.
readDatabase.Messwerte: (models.E004) 'id' can only be used as a field name if the field also sets 'primary_key=True'.
readDatabase.Modifikationen: (models.E004) 'id' can only be used as a field name if the field also sets 'primary_key=True'.
readDatabase.ProteinSequences: (models.E004) 'id' can only be used as a field name if the field also sets 'primary_key=True'.

The last three messages are from tables which were in the original db. All other messages come from tables created by django. I'm using postgresql and confirmed that all tables were created in my database. Below is the output of postgres \dt command to show all tables in the database. This happens when I migrate (python manage.py migrate) the changes.

 variantendatenbank=# \dt
                      Liste der Relationen
 Schema |            Name            |   Typ   |   Eigentümer   
--------+----------------------------+---------+-----------------
 public | auth_group                 | Tabelle | christoph_knapp
 public | auth_group_permissions     | Tabelle | christoph_knapp
 public | auth_permission            | Tabelle | christoph_knapp
 public | auth_user                  | Tabelle | christoph_knapp
 public | auth_user_groups           | Tabelle | christoph_knapp
 public | auth_user_user_permissions | Tabelle | christoph_knapp
 public | b_ids                      | Tabelle | christoph_knapp
 public | bedingungen                | Tabelle | christoph_knapp
 public | django_admin_log           | Tabelle | christoph_knapp
 public | django_content_type        | Tabelle | christoph_knapp
 public | django_migrations          | Tabelle | christoph_knapp
 public | django_session             | Tabelle | christoph_knapp
 public | messwerte                  | Tabelle | christoph_knapp
 public | modifikationen             | Tabelle | christoph_knapp
 public | protein_information        | Tabelle | christoph_knapp
 public | protein_sequences          | Tabelle | christoph_knapp
 public | substrate                  | Tabelle | christoph_knapp
(17 Zeilen)

If anyone could help with the errors from the django tables (maybe also with the problems on my tables)?

I only started yesterday to use django, so let me know if you need anything else.

Christoph
Message has been deleted

Christoph Knapp

unread,
Oct 21, 2015, 10:24:47 AM10/21/15
to Django users
Hi,
the errors disappear when the models.py file is changed by adding _id to the fields defined for the tables where the errors are exist.

As an example for one table I changed


class AuthUserUserPermissions(
models.Model):
    user = models.ForeignKey(AuthUser)
    permission = models.ForeignKey(AuthPermission)

    class Meta:
        db_table = 'auth_user_user_permissions'
        unique_together = ['user_id', 'permission_id']

to

class AuthUserUserPermissions(models.Model):
    user_id = models.ForeignKey(AuthUser)
    permission_id = models.ForeignKey(AuthPermission)

    class Meta:
        db_table = 'auth_user_user_permissions'
        unique_together = ['user_id', 'permission_id']

For some reason when the code for the django tables is generated it does not use the correct field names.

Only the other errors left.

Christoph

Atul kumar Gupta

unread,
Jan 12, 2016, 6:51:07 AM1/12/16
to Django users
Thanks Christoph , Solved my problem.
Love you.
Reply all
Reply to author
Forward
0 new messages