我正在尝试应用教程http://docs.django-cms.org/en/2.1.3/getting_started/tutorial.html.
但我没有成功执行初始数据库设置
为什么运行"python manage.py syncdb --all"时会出现此错误?
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 381, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 230, in execute
self.validate()
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python27\lib\site-packages\django\core\management\validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 158, in get_app_errors
self._populate()
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line …Run Code Online (Sandbox Code Playgroud) 试图查看syncdb将在当前时刻生成的SQL.
经过几次搜索,答案并不明显 - 我知道你可以使用:
python manage.py syncdb --sqlall
Run Code Online (Sandbox Code Playgroud)
收益:
Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created.
Run Code Online (Sandbox Code Playgroud)
如果代码完全改变,如何输出整个数据库发生的更改?
有没有办法为所有需要syncdb'ing的应用程序生成所有SQL?或者我需要明确说明每个应用程序?我不是在寻找整个站点的所有SQL,只是为了实现syncdb实现的更改.
我有几个应用程序需要生成sql来描述更改.我可以明确地列出它们,但syncdb有没有办法为我解决这个问题?
我在Centos VPS上有一个Django项目.
我创建了一些模型并调试它们,以便它们验证并且不会出错.我将它们放在myapp的"models"文件夹中,并将每个模型添加到此目录中的init文件中,例如:
来自类别进口类别
我将应用程序添加到settings.py INSTALLED_APPS并运行:
Python manage.py syncdb
Run Code Online (Sandbox Code Playgroud)
它似乎工作正常,并添加了除我的应用程序之外的所有表.
然后我安装了South并将其添加到INSTALLED_APPS并再次尝试了syncdb并运行:
Python manage.py schemamigration myapp --initial
Run Code Online (Sandbox Code Playgroud)
它正确生成了文件,但没有任何内容(我的模型没有一个表).
"models"文件夹中的示例文件(usertype.py)
from django.db import models
class UserType(models.Model):
usertype_id = models.PositiveIntegerField(primary_key=True)
description = models.CharField(max_length=100)
is_admin = models.BooleanField()
is_moderator = models.BooleanField()
class Meta:
app_label = 'myapp'
Run Code Online (Sandbox Code Playgroud)
任何想法在这里可能会出错,为什么我无法检测到我的模型?
我正在尝试使用post_syncdb信号创建表时立即向数据库添加一些数据.
signals.post_syncdb.connect(init)
Run Code Online (Sandbox Code Playgroud)
然后在init函数中,我想设置权限,所以我使用
ct = ContentType.objects.get(app_label='news', model='Article')
Permission(name='Approve articles', codename='can_approve_article', content_type=ct)
Run Code Online (Sandbox Code Playgroud)
但是,如果我放下所有的桌子并运行syncdb,我会得到
...
File "...\base\functions\init.py", line 11, in init
ct = ContentType.objects.get(app_label='news', model='Article')
...
django.contrib.contenttypes.models.DoesNotExist: ContentType matching query does not exist.
Run Code Online (Sandbox Code Playgroud)
我做过的一些测试:
syncdb.syncdb在没有此代码的情况下创建所有表,它也可以正常工作,然后添加此代码并运行syncdb而无需进行任何更改.非常感谢任何提示!
我在heroku上执行syncdb时遇到问题.我有一个自定义用户模型,当我尝试同步时,heroku给出了这个错误.
django.db.utils.ProgrammingError: relation "auth_group" does not exist
Run Code Online (Sandbox Code Playgroud)
我尝试过python manage.py makemigrations但没有任何问题得到解决.帮我找到解决方案.
我在已安装的应用程序中有django.contrib.auth,大约10分钟前一切正常.我删除了现有的数据库,因为我遇到了南迁移的问题.当我尝试重建它时,我收到一个错误.
错误: django.db.utils.DatabaseError:没有这样的表:auth_user
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 219, in execute
self.validate()
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True) …Run Code Online (Sandbox Code Playgroud) 希望有人可以帮我将django连接到localhost上的mysql数据库...
我已经将Django网站安装到我桌面上的virtualenv文件夹中,然后按照django docs Tutorial的步骤进行操作.
我根据django docs通过pip安装了mysqlclient.
我安装了最新的phpmyadmin并运行WAMP V2.5.
Django测试站点加载localhost:8000,我可以轻松地设置sqli网站.
在localhost/phpmyadmin中,我创建了一个名为"test_db"的空白数据库,作为此问题的一个示例,我使用了username ='user'和password ='pwd'.
我的settings.py文件设置如下,用于数据库设置:
DATABASES = {
'default': 'django.db.backends.mysql',
'NAME': 'test_db',
'HOST': 'localhost',
'PORT': '3306',
'USERNAME': 'user',
'PASSWORD': 'pwd',
}
}
Run Code Online (Sandbox Code Playgroud)
保存settings.py脚本后,运行命令:
python manage.py syncdb
Run Code Online (Sandbox Code Playgroud)
我得到的结果是:
django.db.utils.OperationalError:
(1045, "Access denied for user 'ODBC'@'localhost' (using password: YES)")
Run Code Online (Sandbox Code Playgroud)
我可以将用户名和密码更改为root用户和密码,我仍然可以得到相同的结果.
我花了好几天在谷歌搜索和Youtubing,但到目前为止没有任何帮助...任何帮助赞赏.
我是Django的新手.
我希望我的模型名称以中文显示,所以我在我的模型的元类中使用了verbose_name,代码如下:
#this models.py file is encoded in unicode
class TS_zone(models.Model):
index = models.IntegerField()
zone_name = models.CharField(max_length=50);
zone_icon = models.ImageField(upload_to='zone_icon', null=True)
is_active = models.NullBooleanField(blank=True, null=True)
status = models.CharField(max_length=7,choices=SETTING_STATUS_CHOICES)
class Meta:
ordering = ('index',)
verbose_name = u'????'
verbose_name_plural = u'??????'
def __unicode__(self):
return self.zone_name
Run Code Online (Sandbox Code Playgroud)
但是当我运行manage.py syncdb时,会抛出以下错误:
File "E:\pythonroot\myproject\..\myproject\myapp\models.py", line 19
SyntaxError: Non-ASCII character '\xe4' in file
E:\pythonroot\myproject\..\myproject\myapp\models.py on line 19, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
Run Code Online (Sandbox Code Playgroud)
似乎manage.py无法处理我的verbose_name中的非ascii字符.我做错了什么?
谢谢.
我试图让我的第一个Django项目在Windows上运行,但是我收到一条错误消息:
File "c:\users\[username]\appdata\local\temp\easy_install-pazcre\MySQL_python-1.2.3-py2.7- win32.egg.tmp\MySQLdb\connections.py", line 187, in __init__ mysql_exceptions.OperationalError: (1045, "Access denied for user 'django_user'@'localhost' (using password: YES)")
Run Code Online (Sandbox Code Playgroud)
我从命令行创建了我的数据库:
-- create the database
CREATE DATABASE GlobalXdb CHARACTER SET utf8;
-- create user
CREATE USER 'django_user'@'localhost' IDENTIFIED BY 'thepassword';
-- give user permissions to db
GRANT ALL ON django.* TO 'django_user'@'localhost'
Run Code Online (Sandbox Code Playgroud)
我的settings.py文件包含:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'GlobalXdb', # Or path to database file if using sqlite3.
'USER': …Run Code Online (Sandbox Code Playgroud) 我在Django中创建新数据库时遇到问题:
bash -cl "/Library/Frameworks/Python.framework/Versions/2.7/bin/python /Applications/PyCharm.app/helpers/pycharm/django_manage.py syncdb /Users/hollywoord/PycharmProjects/Gizeh"
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table Raketa_poll
Creating table Raketa_choice
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Traceback (most recent call last):
File "/Applications/PyCharm.app/helpers/pycharm/django_manage.py", line 20, in <module> …Run Code Online (Sandbox Code Playgroud) 我从Django的(Python)的背景和这几天我正在一个项目来了这是基于Laravel(PHP).做我有一个自动生成数据库表中的一些选项?
django ×11
syncdb ×11
python ×5
contenttype ×1
django-south ×1
heroku ×1
laravel ×1
localhost ×1
manage.py ×1
mysql ×1
php ×1
postgresql ×1
pycharm ×1
signals ×1