When I am trying to validate, I am getting this error.
python manage.py validate
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/validate.py", line 9, in handle_noargs
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/google/Myfiles/cheeserater/../cheeserater/packages/models.py", line 4, in <module>
class Package(models.Model):
File "/usr/local/google/Myfiles/cheeserater/../cheeserater/packages/models.py", line 11, in Package
categories = models.ManytoManyField(Category,related_name="packages")
AttributeError: 'module' object has no attribute 'ManytoManyField'
You have a typo:
categories = models.ManyToManyField
You have a typo in ManytoManyField,
It should be ManyToManyField.
Related
$ docker-compose exec myapp python manage.py migrate
I've got this error after modifying my model, how can I rollback or fix the issue ?
Traceback (most recent call last):
File "/src/manage.py", line 21, in <module>
main()
File "/src/manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/opt/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/opt/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/venv/lib/python3.10/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/venv/lib/python3.10/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/opt/venv/lib/python3.10/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/opt/venv/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 268, in handle
emit_post_migrate_signal(
File "/opt/venv/lib/python3.10/site-packages/django/core/management/sql.py", line 42, in emit_post_migrate_signal
models.signals.post_migrate.send(
File "/opt/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 180, in send
return [
File "/opt/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 181, in <listcomp>
(receiver, receiver(signal=self, sender=sender, **named))
File "/opt/venv/lib/python3.10/site-packages/adminactions/models.py", line 9, in create_extra_permissions_handler
p.create_extra_permissions()
File "/opt/venv/lib/python3.10/site-packages/adminactions/perms.py", line 34, in create_extra_permissions
content_types = ContentType.objects.get_for_models(*models)
File "/opt/venv/lib/python3.10/site-packages/django/contrib/contenttypes/models.py", line 89, in get_for_models
opts_models = needed_opts.pop(ct.model_class()._meta, [])
AttributeError: 'NoneType' object has no attribute '_meta'
I have provisioned many servers and deployed this project many times, but this is the first time I have come across this issue.
I can connect to MySQL via command line and Sequel Pro just fine, it's only the Django specific commands that are producing this error.
(Staging)optimal#Simon:/var/virtualenvs/Staging/app$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/django/core/management/base.py", line 219, in execute
self.validate()
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/django/core/management/validation.py", line 36, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/var/virtualenvs/Staging/releases/20130204145734/apps/orpheus/files/models.py", line 17, in <module>
from orpheus.orders.models import Order
File "/var/virtualenvs/Staging/releases/20130204145734/apps/orpheus/orders/models.py", line 29, in <module>
from orpheus.variable_images.models import Newsletter
File "/var/virtualenvs/Staging/releases/20130204145734/apps/orpheus/variable_images/models.py", line 144, in <module>
class Topper(mixins.ModifiedDates):
File "/var/virtualenvs/Staging/releases/20130204145734/apps/orpheus/variable_images/models.py", line 149, in Topper
file = CouchDBFileField(storage=LongTermStorage(), blank=True)
File "/var/virtualenvs/Staging/releases/20130204145734/apps/orpheus/files/storage.py", line 183, in __init__
self.db = server[kwargs.get('database')]
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/couchdb/client.py", line 137, in __getitem__
db.resource.head() # actually make a request to the database
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/couchdb/http.py", line 377, in head
return self._request('HEAD', path, headers=headers, **params)
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/couchdb/http.py", line 419, in _request
credentials=self.credentials)
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/couchdb/http.py", line 239, in request
resp = _try_request_with_retries(iter(self.retry_delays))
File "/var/virtualenvs/Staging/lib/python2.7/site-packages/couchdb/http.py", line 205, in _try_request_with_retries
raise e
socket.error: [Errno 111] Connection refused
I'm just hoping there is an obvious solution that I am overlooking. Hopefully someone else has ran into this problem, I didn't find anything using Google.
from django.db import models
class Post(models.Model):
title = models.CharField(max_length=100)
content = models.CharField(max_length=1000)
created = models.DateField()
modified = models.DateField()
Error for python manage.py syncdb:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 219, in execute
self.validate()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/user1/djangoblog/../djangoblog/blog/models.py", line 7
created = models.DateField()
^
IndentationError: unexpected indent
Did you mix tabs and spaces in the file? That is the most common cause of such an error.
I couldn't help but notice the snippet you posted used tabs. Try the same code indented with spaces.
You probably have spaces or tabs where there needs to be tabs or spaces.
What I was trying to do was to override the save method of one of my models called Shastra
class Shastra(models.Model):
something = models.IntegerField()
def save(self, *args, **kwargs):
post_content(app='shastra', content=self)
super(Shastra, self).save(*args, **kwargs)
# The function being called in the override function
def post_content(*args, **kwargs):
FbApiContent(content = kwargs['content']).save()
# The model being used by the override function
from shastra.models import Shastra
class FbApiContent(models.Model):
content = models.ForeignKey(Shastra)
The Traceback
Traceback (most recent call last):
File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\manage.py", line 14, in <module>
execute_manager(settings)
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
utility.execute()
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 220, in execute
output = self.handle(*args, **options)
File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 67, in handle
self.run(*args, **options)
File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 78, in run
self.inner_run(*args, **options)
File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python26\lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors
self._populate()
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 64, in _populate
self.load_app(app_name)
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "C:\Python26\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\..\kiosk\shastra\models.py", line 10, in <module>
from fb_api.api import *
File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\..\kiosk\fb_api\api.py", line 7, in <module>
from fb_api.models import FbApiUser
File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\..\kiosk\fb_api\models.py", line 41, in <module>
from shastra.models import Shastra
ImportError: cannot import name Shastra
I have no idea what's going on : |, any insights I would be grateful
Circular import. Either resolve it, or use string as FK argument (models.ForeignKey('app.Shastra')).
It looks like you have a circular import.
shastra\models.py is doing from fb_api.api import *
fb_api\api.py is doing from fb_api.models import FbApiUser
fb_api\models.py is doing from shastra.models import Shastra
Even if you just import one class from a module, the whole module gets executed to fill in it's namespace.
This was the traceback, please help.
Traceback (most recent call last):
File "C:\Documents and Settings\EC.32-SAMUEL\workspace\ec\ec\manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
utility.execute()
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 219, in execute
self.validate()
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python26\lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors
self._populate()
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 61, in _populate
self.load_app(app_name, True)
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 83, in load_app
if not module_has_submodule(app_module, 'models'):
File "C:\Python26\lib\site-packages\django\utils\module_loading.py", line 17, in module_has_submodule
for entry in package.__path__: # No __path__, then not a package.
AttributeError: 'module' object has no attribute '
path'
BeautifulSoup is not a Django-app. Its a python package/module. You don't have to add to INSTALLED_APPS. It just need to be available in your PYTHONPATH to use it.
Your traceback doesn't give clue what is actually wrong with your Django project.
The only time you ever need to do a syncdb is when you have to do something to the db. BeautifulSoup does not need to use the db at any point and does not need to be an installed app