Django 1.8 Migrations - NoneType object has no attribute _meta

2024/10/4 3:30:52

Attempting to migrate a project from Django 1.7 to 1.8. After wrestling with code errors, I'm able to get migrations to run. However, when I try to migrate, I'm given the error "'NoneType' object has no attribute '_meta'"

There's no reference in the traceback to any of my apps, so I'm unsure of where exactly to go about looking for the bug (as well as which code to include here so I can be more helpful to those trying to help me)

Here's the full text of the traceback

(venv)rtownley@ubuntu:~/Projects/sparrow1/NJ$ ./manage.py makemigrations
No changes detected
(venv)rtownley@ubuntu:~/Projects/sparrow1/NJ$ ./manage.py migrate
Operations to perform:Synchronize unmigrated apps: staticfiles, editor, djcelery, messages, getty, kombu_transport_django, debug_toolbar, utils, locking, petro, tokenapi, grappelli, django_extensions, selectableApply all migrations: adops, taxonomy, issues, editorial, contenttypes, authors, auth, comms, membership, sessions, bento, urlalias, accounts, breaking_news, easy_thumbnails, images, admin, pages, documents, events
Synchronizing apps without migrations:Creating tables...Running deferred SQL...Installing custom SQL...
Running migrations:Rendering model states...Traceback (most recent call last):File "./manage.py", line 10, in <module>execute_from_command_line(sys.argv)File "/home/rtownley/Projects/sparrow1/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_lineutility.execute()File "/home/rtownley/Projects/sparrow1/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in executeself.fetch_command(subcommand).run_from_argv(self.argv)File "/home/rtownley/Projects/sparrow1/venv/lib/python3.4/site-packages/django/core/management/base.py", line 390, in run_from_argvself.execute(*args, **cmd_options)File "/home/rtownley/Projects/sparrow1/venv/lib/python3.4/site-packages/django/core/management/base.py", line 441, in executeoutput = self.handle(*args, **options)File "/home/rtownley/Projects/sparrow1/venv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 221, in handleexecutor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)File "/home/rtownley/Projects/sparrow1/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 104, in migratestate = migration.mutate_state(state, preserve=do_run)File "/home/rtownley/Projects/sparrow1/venv/lib/python3.4/site-packages/django/db/migrations/migration.py", line 83, in mutate_stateoperation.state_forwards(self.app_label, new_state)File "/home/rtownley/Projects/sparrow1/venv/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 51, in state_forwardsstate.reload_model(app_label, self.model_name_lower)File "/home/rtownley/Projects/sparrow1/venv/lib/python3.4/site-packages/django/db/migrations/state.py", line 97, in reload_modelrelated_models = get_related_models_recursive(old_model)File "/home/rtownley/Projects/sparrow1/venv/lib/python3.4/site-packages/django/db/migrations/state.py", line 57, in get_related_models_recursiverel_app_label, rel_model_name = rel_mod._meta.app_label, rel_mod._meta.model_name
AttributeError: 'NoneType' object has no attribute '_meta'

Other pieces that could potentially be at play: -I have a custom handler that listens for the save event, serializes the data, and creates an identical object in Mongo -Operating out of a virtual environment running Python3.4

Any thoughts on where to go about hunting for the error? Thanks, and sorry I can't provide more code yet!

Answer

Thanks to meiamsome, I figured it out: one of my models had a ForeignKey relationship to a model that no longer existed (I had removed it, and a Git merge had added it back). Thanks for the help all!

https://en.xdnf.cn/q/70658.html

Related Q&A

Manage dependencies of git submodules with poetry

We have a repository app-lib that is used as sub-module in 4 other repos and in each I have to add all dependencies for the sub-module. So if I add/remove a dependency in app-lib I have to adjust all o…

Create Boxplot Grouped By Column

I have a Pandas DataFrame, df, that has a price column and a year column. I want to create a boxplot after grouping the rows based on their year. Heres an example: import pandas as pd temp = pd.DataF…

How can I configure gunicorn to use a consistent error log format?

I am using Gunicorn in front of a Python Flask app. I am able to configure the access log format using the --access-log-format command line parameter when I run gunicorn. But I cant figure out how to c…

Implementing seq2seq with beam search

Im now implementing seq2seq model based on the example code that tensorflow provides. And I want to get a top-5 decoder outputs to do a reinforcement learning.However, they implemented translation mode…

Pandas Random Weighted Choice

I would like to randomly select a value in consideration of weightings using Pandas.df:0 1 2 3 4 5 0 40 5 20 10 35 25 1 24 3 12 6 21 15 2 72 9 36 18 63 45 3 8 1 4 2 7 5 4 16 2 8 4…

Matplotlib TypeError: NoneType object is not callable

Ive run this code many times but now its failing. Matplotlib wont work for any example, even the most trivial. This is the error Im getting, but Im not sure what to make of it. I know this is vague and…

Resize image faster in OpenCV Python

I have a lot of image files in a folder (5M+). These images are of different sizes. I want to resize these images to 128x128. I used the following function in a loop to resize in Python using OpenCVdef…

How to install Yandex CatBoost on Anaconda x64?

Iv successfully installed CatBoost via pip install catboostBut Iv got errors, when I tried sample python script in Jupiter Notebookimport numpy as np from catboost import CatBoostClassifierImportError:…

pyspark returns a no module named error for a custom module

I would like to import a .py file that contains some modules. I have saved the files init.py and util_func.py under this folder:/usr/local/lib/python3.4/site-packages/myutilThe util_func.py contains al…

Perform a conditional operation on a pandas column

I know that this should be simple, but I want to take a column from a pandas dataframe, and for only the entries which meet some condition (say less than 1), multiply by a scalar (say 2).For example, i…