无法使用 djangosyncdb 创建表
我对 django 和 Web 框架开发相当陌生,我厌倦了使用内置 django 模型创建表,然后运行syncdb 命令自动创建它。但是我在创建它时遇到了困难 这是我的模型
from django.db import models
class User(models.Model):
username=models.CharField(max_length=100,primary_key=True)
password=models.CharField(max_length=100)
和数据库配置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'djangousers', # Or path to database file if using sqlite3.
'USER': <my username>, # Not used with sqlite3.
'PASSWORD': <my password>, # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
这是我得到的错误。
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 209, in execute
translation.activate('en-us')
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/__init__.py", line 100, in activate
return _trans.activate(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 202, in activate
_active.value = translation(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 185, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 162, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/thor/scripts/django/quiz/dbs.py", line 4, in <module>
class User(models.Model):
File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py", line 52, in __new__
kwargs = {"app_label": model_module.__name__.split('.')[-2]}
IndexError: list index out of range
任何帮助将不胜感激。提前致谢
I am quite new to django and web framework development and I tired my hands on creating tables by using the inbuilt django models and then running the syncdb command to create it automatically . However I am having trouble creating it
Here is my model
from django.db import models
class User(models.Model):
username=models.CharField(max_length=100,primary_key=True)
password=models.CharField(max_length=100)
And the database configuration
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'djangousers', # Or path to database file if using sqlite3.
'USER': <my username>, # Not used with sqlite3.
'PASSWORD': <my password>, # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
And this is the error I get.
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 209, in execute
translation.activate('en-us')
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/__init__.py", line 100, in activate
return _trans.activate(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 202, in activate
_active.value = translation(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 185, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 162, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/thor/scripts/django/quiz/dbs.py", line 4, in <module>
class User(models.Model):
File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py", line 52, in __new__
kwargs = {"app_label": model_module.__name__.split('.')[-2]}
IndexError: list index out of range
any help would be greatly appreciated . Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎在这里定义您的模型:
/home/thor/scripts/django/quiz/dbs.py
。它应该位于应用模块的根目录中,并命名为
models.py
。有关更多信息,请参阅此处:https://docs.djangoproject。 com/en/dev/topics/db/models/#using-models
You seem to be defining your model here:
/home/thor/scripts/django/quiz/dbs.py
.It should be in the root of your app module and named
models.py
.See here for more info: https://docs.djangoproject.com/en/dev/topics/db/models/#using-models
您知道 Django 有自己的用户模型吗?不要浪费时间做已经完成的事情! (这就是 Django 的全部思想)
更多关于它的信息: https://docs.djangoproject .com/en/1.3/topics/auth/
Did you know that Django have its own User model? don't waste time doing something that is already done! (that's the whole idea of Django)
More about it in: https://docs.djangoproject.com/en/1.3/topics/auth/