How do I add a new model and generate the migrations with South 0.7.2? - django-models

I created a new model:
class RssFeed(models.Model):
url = mdels.CharField(max_length=300)
$ python manage.py schemamigration forum --add-model RssFeed
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/South-0.7.2-py2.7.egg/south/management/commands/schemamigration.py", line 134, in handle
for action_name, params in change_source.get_changes():
File "/usr/local/lib/python2.7/site-packages/South-0.7.2-py2.7.egg/south/creator/changes.py", line 397, in get_changes
real_fields, meta, m2m_fields = self.split_model_def(model, model_defs[model_key(model)])
File "/usr/local/lib/python2.7/site-packages/South-0.7.2-py2.7.egg/south/creator/freezer.py", line 58, in model_key
return "%s.%s" % (model._meta.app_label, model._meta.object_name.lower())
AttributeError: 'NoneType' object has no attribute '_meta'

My syntax was correct, the way I had created the model wasn't.
I had placed all my models into a directory /models
If you do this, you must add Meta to your model definition:
class Meta:
app_label = 'APP_NAME'
If you don't do this, Django can't discover the new models.

Related

I created a virtual environmnt for my new projec, instaled django and started the new project. whnvr I run code with manage.py i get this long error

`when i run line of code: python manage.py startapp blog error below displays
Traceback (most recent call last):
File "C:\Users\lenevo\Desktop\portfolio-project\manage.py", line 22, in <module>
main()
File "C:\Users\lenevo\Desktop\portfolio-project\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\django\core\management_init_.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\django\core\management_init_.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\django\core\management\base.py", line 336, in run_from_argv
connections.close_all()
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\djayour textngo\db\utils.py", line 224, in close_all
connection.close()
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\django\db\backends\sqlite3\base.py", line 248, in close
if not self.is_in_memory_db():
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\django\db\backends\sqlite3\base.py", line 367, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict['NAME'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\django\db\backends\sqlite3\creation.py", line 12, in is_in_memory_db
return database name == ':memory:' or 'mode=memory' in database name
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Type Error: argument of type 'Windows Path' is not Iterable
plz help me solve this problem `

database Django on jython

please i need help connecting database with jython on django and help me with the server when i put jython manage.py runserver the server don´t run
DATABASES = {
'default': {
#'ENGINE': 'doj.backends.zxjdbc.sqlite3',
'ENGINE': 'django.db.backends.mysql',
'NAME': 'tanagraweb',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
and django throw this:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\jython2.7b3\Lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "C:\jython2.7b3\Lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\jython2.7b3\Lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\jython2.7b3\Lib\site-packages\django\core\management\base.py", line 280, in execute
translation.activate('en-us')
File "C:\jython2.7b3\Lib\site-packages\django\utils\translation\__init__.py", line 130, in activate
return _trans.activate(language)
File "C:\jython2.7b3\Lib\site-packages\django\utils\translation\trans_real.py", line 188, in activate
_active.value = translation(language)
File "C:\jython2.7b3\Lib\site-packages\django\utils\translation\trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:\jython2.7b3\Lib\site-packages\django\utils\translation\trans_real.py", line 159, in _fetch
app = import_module(appname)
File "C:\jython2.7b3\Lib\site-packages\django\utils\importlib.py", line 40, in import_module
__import__(name)
File "C:\jython2.7b3\Lib\site-packages\django\contrib\admin\__init__.py", line 6, in <module>
from django.contrib.admin.sites import AdminSite, site
File "C:\jython2.7b3\Lib\site-packages\django\contrib\admin\sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "C:\jython2.7b3\Lib\site-packages\django\contrib\admin\forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "C:\jython2.7b3\Lib\site-packages\django\contrib\auth\forms.py", line 17, in <module>
from django.contrib.auth.models import User
File "C:\jython2.7b3\Lib\site-packages\django\contrib\auth\models.py", line 47, in <module>
#python_2_unicode_compatible
File "C:\jython2.7b3\Lib\site-packages\django\db\models\base.py", line 96, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\jython2.7b3\Lib\site-packages\django\db\models\base.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
File "C:\jython2.7b3\Lib\site-packages\django\db\models\options.py", line 124, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\jython2.7b3\Lib\site-packages\django\db\__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\jython2.7b3\Lib\site-packages\django\db\utils.py", line 198, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\jython2.7b3\Lib\site-packages\django\db\utils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "C:\jython2.7b3\Lib\site-packages\django\db\utils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "C:\jython2.7b3\Lib\site-packages\django\utils\importlib.py", line 40, in import_module
__import__(name)
File "C:\jython2.7b3\Lib\site-packages\django\db\backends\mysql\base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
i research and found that is the connector of mysql but i don´t know why this does´t work
if anyone has a project in jython on django i will be so much gratefull this is too hard
Although MySQLdb is the most widely used MySql library among the Python/Django community, you can't use it because Jython does not work with C extensions.
To use Jython with Django, you need to install django-jython and set the db backend to 'ENGINE': 'doj.db.backends.mysql'
This is documented in the official doc Running Django on Jython
Install pymysql with "pip install pymysql"
Add the following to your manage.py file:
import pymysql
pymysql.install_as_MySQLdb()
In your DATABASES setting, use:
ENGINE': 'django.db.backends.mysql',

Why am I getting MultiQuery exception on 1.4 nonrel?

I'm testing an upgrade on NonRel for App Engine to 1.4 from 1.3. It works fine locally, but when I deploy to App Engine, I get a syncdb error in the end of deployment:
Running syncdb.
2013-08-02 09:31:34,600 WARNING simple_search_stub.py:998 Could not read search indexes from /var/folders/fv/cdp4hprx5pbc_3bf5g0wbbkw0000gn/T/dev_appserver.searchindexes
Creating tables ...
The following content types are stale and need to be deleted:
auth | message
Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.
Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/src/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/src/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/src/djangoappengine/management/commands/deploy.py", line 72, in run_from_argv
run_appcfg(argv)
File "/src/djangoappengine/management/commands/deploy.py", line 51, in run_appcfg
call_command('syncdb', remote=True, interactive=True)
File "/src/django/core/management/__init__.py", line 150, in call_command
return klass.execute(*args, **defaults)
File "/src/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/src/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/src/django/core/management/commands/syncdb.py", line 110, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/src/django/core/management/sql.py", line 189, in emit_post_sync_signal
interactive=interactive, db=db)
File "/src/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/src/django/contrib/contenttypes/management.py", line 67, in update_contenttypes
ct.delete()
File "/src/django/db/models/base.py", line 599, in delete
collector.delete()
File "/src/django/db/models/deletion.py", line 61, in decorated
func(self, *args, **kwargs)
File "/src/django/db/models/deletion.py", line 261, in delete
query.delete_batch([obj.pk for obj in instances], self.using, field)
File "/src/django/db/models/sql/subqueries.py", line 44, in delete_batch
self.do_query(self.model._meta.db_table, where, using=using)
File "/src/django/db/models/sql/subqueries.py", line 29, in do_query
self.get_compiler(using).execute_sql(None)
File "/src/djangotoolbox/db/basecompiler.py", line 593, in execute_sql
self.build_query([self.query.get_meta().pk]).delete()
File "/src/djangoappengine/db/compiler.py", line 69, in _func
return func(*args, **kwargs)
File "/src/djangoappengine/db/compiler.py", line 168, in delete
Delete(keys)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore.py", line 695, in Delete
return DeleteAsync(keys, **kwargs).get_result()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore.py", line 674, in DeleteAsync
keys, _ = NormalizeAndTypeCheckKeys(keys)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore.py", line 176, in NormalizeAndTypeCheckKeys
keys, multiple = NormalizeAndTypeCheck(keys, (basestring, Entity, Key))
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore.py", line 143, in NormalizeAndTypeCheck
arg_list = list(arg)
File "/src/djangoappengine/db/compiler.py", line 105, in fetch
query = self._build_query()
File "/src/djangoappengine/db/compiler.py", line 69, in _func
return func(*args, **kwargs)
File "/src/djangoappengine/db/compiler.py", line 322, in _build_query
return MultiQuery(self.gae_query, self.ordering)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore.py", line 1998, in __init__
'MultiQuery does not support keys_only.')
django.db.utils.DatabaseError: MultiQuery does not support keys_only.
I am able to work around it by deleting the content types on my local development server, but I'm wondering why I'm getting this error. I do understand what the exception says, but don't understand why NonRel has not adapted Django to perform this operation properly in App Engine?
This could be a bug in a path of the djangoappengine compiler that isn't utilized much. There was another delete related bug a few months ago:
https://groups.google.com/forum/#!searchin/django-non-relational/delete/django-non-relational/Eb6K7fVYrhM/_QmLPtbIfmMJ
That being said, I'm not even sure why djangoappengine runs syncdb at all when you deploy. It runs syncdb locally, not on the production server. It seems unnecssary, I suspect it's just a byproduct of some existing django codepath.
I encontered a simillar error can you try
./manage.py sqlflush

django call_command syncdb failed: unable to open database file

I want to add some python codes after syncdb, so I decide to write a build.py which does everything including syncdb.
I write something in build.py as:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.management import call_command
from django.contrib.auth.models import User
call_command('syncdb', interactive=False)
But when I run build.py, it said:
Traceback (most recent call last):
File "/home/csimstu/PycharmProjects/TeenHope/TeenHope/build.py", line 5, in <module>
call_command('syncdb', interactive=False)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 161, in call_command
return klass.execute(*args, **defaults)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 255, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 385, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 56, in handle_noargs
cursor = connection.cursor()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 324, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 306, in _cursor
self._sqlite_create_connection()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 296, in _sqlite_create_connection
self.connection = Database.connect(**kwargs)
sqlite3.OperationalError: unable to open database file
I've tried ./manage.py syncdb and use call_command in interactive shell mode, and both ways worked perfectly okay. How could it be?
If the database file isn't found that's probably because you didn't use a full path in your settings.
import os
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.realpath(os.path.join(os.path.dirname(__file__), "relative_path_here", "database.db")),
Out of topic: I'd recommend to use Fabric for this kind of commands.

South migration schemamigration doesn't work

Just to make sure I have the setup right in my current django project, I did the following:
added south to installed_apps
manage.py syncdb (using windows)
manage.py convert_to_south app
I didn't make changes to my database yet but whether or not I do, I run:
manage.py schemamigration app --auto
and I get the following errors:
Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 443, in execute
_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196, in run_from_ar
gv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\south\management\commands\schemamigration.py", line 98, i
n handle
old_orm = last_migration.orm(),
File "C:\Python27\lib\site-packages\south\utils.py", line 62, in method
value = function(self)
File "C:\Python27\lib\site-packages\south\migration\base.py", line 418, in orm
return FakeORM(self.migration_class(), self.app_label())
File "C:\Python27\lib\site-packages\south\orm.py", line 46, in FakeORM
_orm_cache[args] = _FakeORM(*args)
File "C:\Python27\lib\site-packages\south\orm.py", line 125, in __init__
self.models[name] = self.make_model(app_label, model_name, data)
File "C:\Python27\lib\site-packages\south\orm.py", line 318, in make_model
field = self.eval_in_context(code, app, extra_imports)
File "C:\Python27\lib\site-packages\south\orm.py", line 236, in eval_in_context
return eval(code, globals(), fake_locals)
File "<string>", line 1
SouthFieldClass(default=datetime.datetime(2012, 9, 14, 20, 46, 3, 957000, tzinfo=<UTC>))
^
SyntaxError: invalid syntax
What's going on?
It's not letting me use schemamigration. Been searching a lot of places and deleting and resetting the database and everything, can't seem to find out what the problem is.
Problem resolved:
Didn't know about south_migrationhistory location. I was always wondering about where some extra information was hanging.
Have a look here: http://south.aeracode.org/ticket/1069
Its a bug that is fixed in newer South versions. It seems you are using an obsolete version of South(<=0.7.3)

Resources