Django 1.11执行makemigrations提示无变更问题求助
Hey there, I’ve dealt with this exact frustrating issue a few times when working with older Django versions like 1.11. Let’s walk through the most likely fixes to get your BModel picked up:
1. Double-check your app is registered in settings.py
Django only scans models from apps listed in INSTALLED_APPS. Open your project’s settings.py and make sure 'connection' is included:
INSTALLED_APPS = [ # ... other existing apps 'connection', ]
If it was missing, add it, save the file, and re-run python manage.py makemigrations connection.
2. Verify your BModel definition is correct and saved
It sounds obvious, but let’s rule out simple missteps:
- Your model must inherit from
models.Model—this is a non-negotiable for Django to recognize it:class BModel(models.Model): # Example field, adjust to your needs name = models.CharField(max_length=100) - Ensure you’ve saved
connection/models.py—some editors don’t auto-save, and Django won’t detect unsaved changes. - Scan for syntax errors (a missing comma, typo, or unclosed bracket can silently prevent model detection).
3. Reset stale migration files and database records
Old migration artifacts can sometimes block new changes:
- Delete all files in
connection/migrations/except__init__.py. - Access your database (via
python manage.py shellor a DB client) and delete all rows in thedjango_migrationstable whereapp = 'connection'. - Run
python manage.py makemigrations connectionagain to generate a fresh initial migration.
4. Confirm you’re using the correct Python environment
Ubuntu 14.04 often has multiple Python versions pre-installed. If you’re using a virtual environment, activate it first:
# Adjust the path to match your virtual environment source /path/to/your/env/bin/activate python manage.py makemigrations connection
You can verify the Django version in your active environment with python -m django --version to ensure it’s 1.11.
5. Clear Django’s bytecode cache
Stale cached code can sometimes hide model changes:
- Delete all
__pycache__folders in your project (both the root directory and theconnectionapp folder). - Re-run the
makemigrationscommand.
6. Double-check the model’s location
Make 100% sure BModel is defined in connection/models.py—it’s easy to accidentally paste code into the wrong app’s models file by mistake!
If none of these fixes work, sharing your full models.py code and existing migration files would help narrow down the issue further.
内容的提问来源于stack exchange,提问作者DirtyHands

