./manage makemigrations and ./manage migrate don't work

24 views
Skip to first unread message

Mohsen Pahlevanzadeh

unread,
Jun 19, 2020, 2:40:57 AM6/19/20
to Django users
I run :
./manage makemigrations and ./manage migrate with the following output:
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(django_sql) mohsen@debian:~/Documents/django_sql/django_sql$ ./manage.py makemigrations
Migrations for 'sql':
  sql/migrations/0006_customertbl_employeepaytbl_employeetbl_orderstbl_productstbl.py
    - Create model CustomerTbl
    - Create model EmployeeTbl
    - Create model OrdersTbl
    - Create model ProductsTbl
    - Create model EmployeePayTbl
(django_sql) mohsen@debian:~/Documents/django_sql/django_sql$ ./manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions, sql
Running migrations:
  Applying sql.0006_customertbl_employeepaytbl_employeetbl_orderstbl_productstbl... OK
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
My models.py is:

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
from django.db import models

# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
#   * Rearrange models' order
#   * Make sure each model has one field with primary_key=True
#   * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior
#   * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.


class CustomerTbl(models.Model):
    cust_id = models.CharField(db_column='CUST_ID', primary_key=True, max_length=10)  # Field name made lowercase.
    cust_name = models.CharField(db_column='CUST_NAME', max_length=30)  # Field name made lowercase.
    cust_address = models.CharField(db_column='CUST_ADDRESS', max_length=20)  # Field name made lowercase.
    cust_city = models.CharField(db_column='CUST_CITY', max_length=15)  # Field name made lowercase.
    cust_state = models.CharField(db_column='CUST_STATE', max_length=2)  # Field name made lowercase.
    cust_zip = models.IntegerField(db_column='CUST_ZIP')  # Field name made lowercase.
    cust_phone = models.CharField(db_column='CUST_PHONE', max_length=10, blank=True, null=True)  # Field name made lowercase.
    cust_fax = models.CharField(db_column='CUST_FAX', max_length=10, blank=True, null=True)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 'CUSTOMER_TBL'


class EmployeePayTbl(models.Model):
    emp = models.OneToOneField('EmployeeTbl', models.DO_NOTHING, db_column='EMP_ID', primary_key=True)  # Field name made lowercase.
    position = models.CharField(db_column='POSITION', max_length=15)  # Field name made lowercase.
    date_hire = models.DateField(db_column='DATE_HIRE', blank=True, null=True)  # Field name made lowercase.
    pay_rate = models.DecimalField(db_column='PAY_RATE', max_digits=4, decimal_places=2, blank=True, null=True)  # Field name made lowercase.
    date_last_raise = models.DateField(db_column='DATE_LAST_RAISE', blank=True, null=True)  # Field name made lowercase.
    salary = models.DecimalField(db_column='SALARY', max_digits=8, decimal_places=2, blank=True, null=True)  # Field name made lowercase.
    bonus = models.DecimalField(db_column='BONUS', max_digits=6, decimal_places=2, blank=True, null=True)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 'EMPLOYEE_PAY_TBL'


class EmployeeTbl(models.Model):
    emp_id = models.CharField(db_column='EMP_ID', primary_key=True, max_length=9)  # Field name made lowercase.
    last_name = models.CharField(db_column='LAST_NAME', max_length=15)  # Field name made lowercase.
    first_name = models.CharField(db_column='FIRST_NAME', max_length=15)  # Field name made lowercase.
    middle_name = models.CharField(db_column='MIDDLE_NAME', max_length=15, blank=True, null=True)  # Field name made lowercase.
    address = models.CharField(db_column='ADDRESS', max_length=30)  # Field name made lowercase.
    city = models.CharField(db_column='CITY', max_length=15)  # Field name made lowercase.
    state = models.CharField(db_column='STATE', max_length=2)  # Field name made lowercase.
    zip = models.IntegerField(db_column='ZIP')  # Field name made lowercase.
    phone = models.CharField(db_column='PHONE', max_length=10, blank=True, null=True)  # Field name made lowercase.
    pager = models.CharField(db_column='PAGER', max_length=10, blank=True, null=True)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 'EMPLOYEE_TBL'


class OrdersTbl(models.Model):
    ord_num = models.CharField(db_column='ORD_NUM', primary_key=True, max_length=10)  # Field name made lowercase.
    cust_id = models.CharField(db_column='CUST_ID', max_length=10)  # Field name made lowercase.
    prod_id = models.CharField(db_column='PROD_ID', max_length=10)  # Field name made lowercase.
    qty = models.IntegerField(db_column='QTY')  # Field name made lowercase.
    ord_date = models.DateField(db_column='ORD_DATE', blank=True, null=True)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 'ORDERS_TBL'


class ProductsTbl(models.Model):
    prod_id = models.CharField(db_column='PROD_ID', primary_key=True, max_length=10)  # Field name made lowercase.
    prod_desc = models.CharField(db_column='PROD_DESC', max_length=40)  # Field name made lowercase.
    cost = models.DecimalField(db_column='COST', max_digits=6, decimal_places=2)  # Field name made lowercase.

    class Meta:
         managed = False
         db_table = 'PRODUCTS_TBL'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

But When I use the following command in mysql shell:
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
use esql;
show tables;
+----------------------------+
| Tables_in_esql             |
+----------------------------+
| auth_group                 |
| auth_group_permissions     |
| auth_permission            |
| auth_user                  |
| auth_user_groups           |
| auth_user_user_permissions |
| django_admin_log           |
| django_content_type        |
| django_migrations          |
| django_session             |
+----------------------------+


I don't see my tables.

What happen?


Jatin Agrawal

unread,
Jun 20, 2020, 4:09:34 PM6/20/20
to Django users
The reason for this is, in class Meta, you have set, managed=False. That's causing the issue. 

When you set managed=False, then there is no table creation happens for that model when you run migrate command after make migrations. So, if you want a table to be created for that model, just remove managed=False and it should work fine.

Refer the django docs for more details: https://docs.djangoproject.com/en/2.2/ref/models/options/
Reply all
Reply to author
Forward
0 new messages