Error: django.db.migrations.exceptions.InconsistentMigrationHistory

Below is my Error message and docker-compose.yml file.
I am trying to run 3 Django Projects as Services which handles services like Printing, Inspection,etc… as you can see in .yml file when I am building it.

The Problems that i am facing is

  1. It only catches the cartonprintingsystem manage.py and it skips the file of other services and it happens for Dockerfile,requirements.txt as well. How to handle this issue.
  2. I tried to manual create manage.py for inspection and I think it does not copies the manage.py file of other services that why it giving me this error.
# python manage_inspection.py makemigrations
System check identified some issues:

WARNINGS:
inspectionactivity.SesUser.session_number: (fields.W122) 'max_length' is ignored when used with BigIntegerField.
        HINT: Remove 'max_length' from field
Traceback (most recent call last):
  File "/app/manage_inspection.py", line 22, in <module>
    main()
  File "/app/manage_inspection.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 106, in wrapper
    res = handle_func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py", line 156, in handle
    loader.check_consistent_history(connection)
  File "/usr/local/lib/python3.9/site-packages/django/db/migrations/loader.py", line 327, in check_consistent_history
    raise InconsistentMigrationHistory(
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency inspectionactivity.0001_initial on database 'default'```
version: '3.8'

services:
  cartonprintingsystem:
    build: 
      context: ./cartonprintingsystem
      dockerfile: Dockerfile
    command: python manage.py runserver 0.0.0.0:8000
    ports:
      - "8000:8000"
    # volumes:
    #   - ./cartonprintingsystem:/app
    volumes:
      - carton-printing-volume:/app 
    networks:
      - Carton

  inspection_service:
    build:
      context: ./inspection_service
      dockerfile: Dockerfile
    command: python manage.py runserver 0.0.0.0:8001
    ports:
      - "8001:8001"
    volumes:
      - carton-printing-volume:/app 
    environment:
      - DJANGO_SETTINGS_MODULE=inspection_service.settings
    networks:
      - Carton

  printing_service:
    build:
      context: ./printing
      dockerfile: Dockerfile
    command: python manage.py runserver 0.0.0.0:8002
    ports:
      - "8002:8002"
    volumes:
      - carton-printing-volume:/app 
    networks:
      - Carton

  phpMyAdmin:
    image: phpmyadmin
    environment:
      PMA_ARBITRARY: 1
    ports:
      - "9090:80"

  broker:
    image: confluentinc/cp-kafka:7.5.0
    container_name: broker
    ports:
      - "9092:9092"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
      KAFKA_PROCESS_ROLES: broker,controller
      KAFKA_NODE_ID: 1
      KAFKA_CONTROLLER_QUORUM_VOTERS: 1@broker:29093
      KAFKA_LISTENERS: PLAINTEXT://broker:29092,CONTROLLER://broker:29093,PLAINTEXT_HOST://0.0.0.0:9092
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
      KAFKA_LOG_DIRS: /tmp/kraft-combined-logs
      CLUSTER_ID: MkU3OEVBNTcwNTJENDM2Qk
    networks:
      - Carton

volumes:
  carton-printing-volume:

networks:
  Carton:

Please post your Dockerfile for each of these services, along with a description of your intended directory structure for your containers.

Also, please be more explicit in describing the issues.

For example, what you do mean by:

What is the “it” you’re referring to in the first sentence? What do you mean by “catches” here?

Finally, did you inspect your docker volume to see what is in it? Can you identify specifically what is missing?

These are my Dockerfiles for services.

It only catches the cartonprintingsystem manage.py and it skips the file of other services and it happens for Dockerfile,requirements.txt as well. How to handle this issue.

To Elaborate the above sentence for more detail:
When I run docker-compose up in the volume[carton-printing-volume:]. I can only see manage.py file from Cartonprintingsystem service not from other services same case scenario for Dockerfile,requirements,etc… .

This is My Project Structure:

.
├── cartonprintingsystem
│   ├── Dockerfile
│   ├── Pipfile
│   ├── Pipfile.lock
│   ├── accounts
│   ├── cartonprintingsystem
│   ├── configuration
│   ├── dashboard
│   ├── db_carton_printing (11).sql
│   ├── manage.py
│   ├── media
│   ├── printingactivity
│   ├── productgeneration
│   ├── readme.md
│   ├── requirements.txt
│   ├── serialnoInspection
│   ├── static
│   ├── templates
│   └── venv
├── compose-dev.yaml
├── docker-compose.yml
├── env
│   ├── Include
│   ├── Lib
│   ├── Scripts
│   └── pyvenv.cfg
├── inspection_service
│   ├── Dockerfile
│   ├── consumer.py
│   ├── db.sqlite3
│   ├── getting_started.ini
│   ├── inspection_service
│   ├── inspectionactivity
│   ├── manage.py
│   ├── requirements.txt
│   └── templates
└── printing
    ├── Dockerfile
    ├── manage.py
    ├── printing
    └── requirements.txt
# Use an official Python runtime as a parent image
FROM python:3.9

# Set environment variables for Python and Django
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE=cartonprintingsystem.settings

# Create and set the working directory
WORKDIR /app

RUN apt update && apt install -y libzbar0
RUN apt install -y libgl1-mesa-glx
RUN apt install libdmtx0b
RUN pip install --upgrade pip
RUN pip install Django pandas numpy opencv-python grpcio-tools grpcio djangorestframework django-crispy-forms daphne mysqlclient pyzbar crispy-bootstrap4 pylibdmtx pytesseract qrcode
# Copy the project code into the container
COPY requirements.txt /app/requirements.txt

# Install project dependencies
RUN pip install -r requirements.txt

# Copy the entire project directory into the container
COPY . /app/



FROM python:3.9

# Set environment variables
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE inspection_service.settings

# Create and set the working directory
WORKDIR /app
RUN apt update && apt install -y libzbar0
RUN apt install -y libgl1-mesa-glx
RUN apt install libdmtx0b
RUN pip install --upgrade pip
RUN pip install Django pandas numpy opencv-python grpcio-tools grpcio djangorestframework django-crispy-forms daphne mysqlclient pyzbar crispy-bootstrap4 pylibdmtx pytesseract qrcode
# Copy the project code into the container
COPY requirements.txt /app/requirements.txt
# Install project dependencies
RUN pip install -r requirements.txt
COPY . /app/

FROM python:3.9

# Set environment variables
ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE printing.settings

# Create and set the working directory
WORKDIR /app
RUN apt update && apt install -y libzbar0
RUN apt install -y libgl1-mesa-glx
RUN apt install libdmtx0b
RUN pip install --upgrade pip
RUN pip install Django pandas numpy opencv-python grpcio-tools grpcio djangorestframework django-crispy-forms daphne mysqlclient pyzbar crispy-bootstrap4 pylibdmtx pytesseract qrcode
# Copy the project code into the container
COPY requirements.txt /app/requirements.txt
# Install project dependencies
RUN pip install -r requirements.txt
COPY . /app/

Please read my previous reply at How to add a new Django Project to the Existing sytem in Docker using yml - #4 by KenWhitesell, along with the referenced Docker docs.

Docker containers and volumes do not work the way you’re expecting, and how you’re constructing your application isn’t going to work.

If you’re going to use one common volume for all your components, you need to build that volume completely within one container. Also, you’ll need to ensure that the volume has been deleted when you update your project to ensure it gets reinitialized.

Finally, you should stop using runserver for your project if you’re expecting this to be reliable in a deployed environment.