from __future__ import unicode_literals
from django.db import models
# Create your simplesite models here.
class simplesite(models.Model):
name=models.CharField(max_length=100)
due_date=models.DateTimeField()
#simplest app model
class simplest(models.Model):
simple_site=models.foreignkey(simplesite)
name=models.CharField(max_length=100)
due_date=models.DateTimeField()
This is the error displayed when i run this command: python .\manage.py makemigrations simplest
PS C:\django\simplesite> python .\manage.py makemigrations simplest
Traceback (most recent call last):
File ".\manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 341, in execute
django.setup()
File "C:\Python27\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Python27\lib\site-packages\django\apps\config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\django\simplesite\simplest\models.py", line 9
due_date=models.DateTimeField()
^
IndentationError: unindent does not match any outer indentation level
any please help i am stack on that place .i am a beginner in python django framework
This is a basic python syntax issue. Make sure you have not mixed spaces and tabs in your indentation.
You have to configure your editor to be 4 spaces by tab and not only tab, because four spaces for python is not the same that one tab.
You have to make sure that all the code is using four spaces the code
I have a model in one of my apps which is throwing an error when I run "python.py makemigrations signup." I have spent the last two days pouring through documentation (and Google) trying to figure out why this error is happening. Unfortunately I have come up with nothing.
What I am trying to do is include an app in my project. The app sits in the root directory of my python directory (not in a subfolder of of my project). Here is my code:
from django.db import models
class CompanyInfo(models.Model):
companyID = model.AutoField(primary_key=True)
companyName = model.CharField(max_length=100)
companyURL = model.URLField(max_length=100)
companyEmail = model.EmailField(max_length=254)
companyFEIN = model.CharField(max_length=50)
companyUsername= model.CharField(max_length=100)
companyPassword = model.CharField(max_length=100)
class CompanyContact(models.Model):
ccID = model.AutoField(primary_key=True)
ccFirstName = model.CharField(max_length=100)
ccLastName = model.CharField(max_length=100)
ccEmail = model.EmailField(max_length=254)
ccPhone = model.IntegerField(max_length=20)
The exact error that is printed to the console reads:
root#ubuntu1204:/home/humanoid# python manage.py makemigrations humanoid
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/humanoid/signup/models.py", line 3, in <module>
class CompanyInfo(models.Model):
File "/home/humanoid/signup/models.py", line 4, in CompanyInfo
companyID = model.AutoField(primary_key=True)
NameError: name 'model' is not defined
It looks like you have dropped the 's' on models. You need to change your use of model to models.
For example:
companyID = model.AutoField(primary_key=True)
Needs to be:
companyID = models.AutoField(primary_key=True)
It looks like from the import it should be models (plural) and not model.
I just generated the migration scripts through ./manage.py schemamigration --auto and ran it. I get the following error. I am stumped as to what it could mean. I have been using SET_NULL for a while now. So this is something new that didn't occur earlier. Any idea what could be wrong?
Traceback (most recent call last):
File "./manage.py", line 16, in
execute_from_command_line(sys.argv)
File "/home/vivekv/.environments/fantain/local/lib/python2.7/site-packages/django/core/management/init.py", line 399, in execute_from_command_line
utility.execute()
File "/home/vivekv/.environments/fantain/local/lib/python2.7/site-packages/django/core/management/init.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vivekv/.environments/fantain/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.dict)
File "/home/vivekv/.environments/fantain/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/home/vivekv/.environments/fantain/local/lib/python2.7/site-packages/south/management/commands/schemamigration.py", line 111, in handle
old_orm = last_migration.orm(),
File "/home/vivekv/.environments/fantain/local/lib/python2.7/site-packages/south/utils/init.py", line 62, in method
value = function(self)
File "/home/vivekv/.environments/fantain/local/lib/python2.7/site-packages/south/migration/base.py", line 432, in orm
return FakeORM(self.migration_class(), self.app_label())
File "/home/vivekv/.environments/fantain/local/lib/python2.7/site-packages/south/orm.py", line 48, in FakeORM
_orm_cache[args] = _FakeORM(*args)
File "/home/vivekv/.environments/fantain/local/lib/python2.7/site-packages/south/orm.py", line 134, in init
self.retry_failed_fields()
File "/home/vivekv/.environments/fantain/local/lib/python2.7/site-packages/south/orm.py", line 377, in retry_failed_fields
fname, modelname, e
ValueError: Cannot successfully create field 'winner' for model 'match': 'module' object has no attribute 'SET_NULL'.
OK This is not a valid question. I am embarrassed to admit I made a small tweak on the migration script that caused the problem. Please ignore this question - seems like I dont have a way to delete a question I had asked!
I wrote the solution here
Short answer: use models.SET_NULL instead of "SET_NULL".
You need to replace this in all migrations which have b"SET_NULL"
I am using Sphinx to automatically build docs for a project I am working on. The docs were building fine, until I added another class to one of the modules. Now whenever I try to run the build, the new class is not imported.
The error from the Sphinx error log:
# Sphinx version: 1.2b3
# Python version: 2.7.3
# Docutils version: 0.9 release
# Jinja2 version: 2.6
# Loaded extensions:
# sphinxcontrib.httpdomain from C:\Python27\lib\site-packages\sphinxcontrib_httpdomain-1.2.1-py2.7.egg\sphinxcontrib\httpdomain.pyc
# sphinxcontrib.autohttp.flask from C:\Python27\lib\site-packages\sphinxcontrib_httpdomain-1.2.1-py2.7.egg\sphinxcontrib\autohttp\flask.pyc
# sphinx.ext.autodoc from C:\Python27\lib\site-packages\sphinx\ext\autodoc.pyc
# sphinx.ext.viewcode from C:\Python27\lib\site-packages\sphinx\ext\viewcode.pyc
# sphinx.ext.oldcmarkup from C:\Python27\lib\site-packages\sphinx\ext\oldcmarkup.pyc
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\sphinx\cmdline.py", line 246, in main
app.build(force_all, filenames)
File "C:\Python27\lib\site-packages\sphinx\application.py", line 212, in build
self.builder.build_update()
File "C:\Python27\lib\site-packages\sphinx\builders\__init__.py", line 214, in build_update
'out of date' % len(to_build))
File "C:\Python27\lib\site-packages\sphinx\builders\__init__.py", line 234, in build
purple, length):
File "C:\Python27\lib\site-packages\sphinx\builders\__init__.py", line 134, in status_iterator
for item in iterable:
File "C:\Python27\lib\site-packages\sphinx\environment.py", line 470, in update_generator
self.read_doc(docname, app=app)
File "C:\Python27\lib\site-packages\sphinx\environment.py", line 618, in read_doc
pub.publish()
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\core.py", line 221, in publish
self.settings)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\readers\__init__.py", line 69, in read
self.parse()
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\readers\__init__.py", line 75, in parse
self.parser.parse(self.input, document)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\__init__.py", line 162, in parse
self.statemachine.run(inputlines, document, inliner=self.inliner)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 174, in run
input_source=document['source'])
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\statemachine.py", line 239, in run
context, state, transitions)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 2706, in underline
self.section(title, source, style, lineno - 1, messages)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 331, in section
self.new_subsection(title, lineno, messages)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 399, in new_subsection
node=section_node, match_titles=True)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 286, in nested_parse
node=node, match_titles=match_titles)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 199, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\statemachine.py", line 239, in run
context, state, transitions)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 2706, in underline
self.section(title, source, style, lineno - 1, messages)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 331, in section
self.new_subsection(title, lineno, messages)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 399, in new_subsection
node=section_node, match_titles=True)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 286, in nested_parse
node=node, match_titles=match_titles)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 199, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\statemachine.py", line 239, in run
context, state, transitions)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 2279, in explicit_markup
nodelist, blank_finish = self.explicit_construct(match)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 2291, in explicit_construct
return method(self, expmatch)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 2034, in directive
directive_class, match, type_name, option_presets)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 2083, in run_directive
result = directive_instance.run()
File "C:\Python27\lib\site-packages\sphinxcontrib_httpdomain-1.2.1-py2.7.egg\sphinxcontrib\autohttp\flask.py", line 138, in run
for line in self.make_rst():
File "C:\Python27\lib\site-packages\sphinxcontrib_httpdomain-1.2.1-py2.7.egg\sphinxcontrib\autohttp\flask.py", line 97, in make_rst
app = import_object(self.arguments[0])
File "C:\Python27\lib\site-packages\sphinxcontrib_httpdomain-1.2.1-py2.7.egg\sphinxcontrib\autohttp\common.py", line 17, in import_object
mod = __import__(module_name)
File "E:\workspace_zach\API\api_serve.py", line 6, in <module>
from BOBI import BOBI
File "E:\workspace_zach\API\BOBI\__init__.py", line 13, in <module>
from Lib.DBVersionTools import DBVersionNormalizer, DBVersionPolisher
ImportError: cannot import name DBVersionPolisher
The module is on the path, and is within a folder with an __init__.py file. Sphinx is clearly able to import the first class, but not the second. Tests involving both classes work fine. I have deleted all of the old .pyc files, but that failed to resolve the issue. If I remove the second class from the import statement and comment out references to it, then the docs work without a problem.
Any ideas on how to fix this issue, or failing that hide the import statements from sphinx (but not other scripts, like my tests)?
Additional code:
All import statements:
import Error
import logging
import re
import Lib.globals as Globals
from flask import Blueprint, jsonify, request, current_app, make_response
from functools import update_wrapper
from datetime import timedelta
from Lib.VerifyCookie import verify, req_to_dict
from Lib.MSSQLTools import MSSQLTools
from Lib.DBVersionTools import DBVersionNormalizer, DBVersionPolisher
Sphinx extensions and path modifications:
sys.path.append('E:\\workspace_zach\\API') # Root directory for the project
extensions = [
'sphinx.ext.autodoc',
'sphinxcontrib.httpdomain',
'sphinxcontrib.autohttp.flask',
'sphinx.ext.autodoc',
'sphinx.ext.viewcode',
]
A previous version of the file, without the modifications being imported, existed on another path of the computer I was developing on, and had been added to the pythonpath.
sys.path.remove('E:\\workspace\\API') was sufficient to remove the other path and fix the problem.
I've followed numerous tutorials on how to setup a Django project with MongoDB but still get the same errors when running the command for testing:
python manage.py runsever
Here is the link I've been following:
http://www.allbuttonspressed.com/blog/django/2010/05/MongoDB-backend-for-Django-nonrel-released
Here are the errors I get from the above command:
Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10d266210>>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 23, in get_validation_errors
from django.db import models, connection
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 24, in load_backend
return import_module('.base', backend_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "build/bdist.macosx-10.8-intel/egg/django_mongodb_engine/__init__.py", line 13, in <module>
AttributeError: 'tuple' object has no attribute 'insert'
I have no idea why this isn't working and ideally I just want a database setup to use specifically for storing JSON documents. Is there an easier alternative to connecting Django with another database that is ideal for storing JSON information?
For clarification:
INSTALLED_APPS should be tuple.
He gets AttributeError: 'tuple' object has no attribute 'insert' because mongodb does not handle tuple INSTALLED_APPS correctly. The default in mongodb is insert list. This is already fix before but now it's gone.
There suggestion are:
changing your settings.INSTALLED_APPS to a list instead of a tuple. (which is bad for me)
correct their code by adding the patch
There is a new package called djongo for fully nosql support with mongoDB:
- https://nesdis.github.io/djongo/
you cann install ist in your venv:
pip install djongo