gorf / pydiary

Automatically exported from code.google.com/p/pydiary
GNU General Public License v2.0
1 stars 0 forks source link

django1.3下报错 #1

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

Please use labels and text to provide additional information.

ValueError at /admin/blog/post/add/
'Post' instance needs to have a primary key value before a many-to-many 
relationship can be used.
Request Method: POST
Request URL:    http://test.gentoogle.com/admin/blog/post/add/
Django Version: 1.3.1
Exception Type: ValueError
Exception Value:    
'Post' instance needs to have a primary key value before a many-to-many 
relationship can be used.
Exception 
Location:   /usr/lib64/python2.7/site-packages/django/db/models/fields/related.py 
in __init__, line 493
Python Executable:  /usr/bin/python2.7
Python Version: 2.7.2
Python Path:    
['/home/lq/pylogs',
 '/usr/lib64/python27.zip',
 '/usr/lib64/python2.7',
 '/usr/lib64/python2.7/plat-linux2',
 '/usr/lib64/python2.7/lib-tk',
 '/usr/lib64/python2.7/lib-old',
 '/usr/lib64/python2.7/lib-dynload',
 '/usr/lib64/python2.7/site-packages',
 '/usr/lib64/python2.7/site-packages/PIL',
 '/usr/lib64/python2.7/site-packages/gst-0.10',
 '/usr/lib64/python2.7/site-packages/gtk-2.0',
 '/usr/lib64/portage/pym',
 '/home/lq/pylogs/utils',
 '/home/lq/pylogs/utils']
Server time:    星期二, 8 十一月 2011 18:16:01 +0800
Traceback Switch to copy-and-paste view

/usr/lib64/python2.7/site-packages/django/core/handlers/base.py in get_response
                        response = callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/contrib/admin/options.py in wrapper
                return self.admin_site.admin_view(view)(*args, **kwargs) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/utils/decorators.py in _wrapped_view
                    response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/views/decorators/cache.py in 
_wrapped_view_func
        response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/contrib/admin/sites.py in inner
            return view(request, *args, **kwargs) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/utils/decorators.py in _wrapper
            return bound_func(*args, **kwargs) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/utils/decorators.py in _wrapped_view
                    response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/utils/decorators.py in bound_func
                return func(self, *args2, **kwargs2) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/db/transaction.py in inner
                res = func(*args, **kwargs) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/contrib/admin/options.py in add_view
                self.save_model(request, new_object, form, change=False) ...
▶ Local vars
/home/lq/pylogs/blog/admin.py in save_model
            form.save_m2m()
 ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/forms/models.py in save_m2m
                f.save_form_data(instance, cleaned_data[f.name]) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/db/models/fields/related.py in 
save_form_data
        setattr(instance, self.attname, data) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/db/models/fields/related.py in __set__
        manager = self.__get__(instance) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/db/models/fields/related.py in __get__
            reverse=False ...
▶ Local vars
/usr/lib64/python2.7/site-packages/django/db/models/fields/related.py in 
__init__
                raise ValueError("%r instance needs to have a primary key value before a many-to-many relationship can be used." % instance.__class__.__name__) ...
▶ Local vars
Request information

GET
No GET data
POST
Variable    Value
title   
u'sdf'
post_status 
u'draft'
markup  
u'html'
post_name   
u'sdf'
_continue   
u'\u4fdd\u5b58\u5e76\u7ee7\u7eed\u7f16\u8f91'
content 
u'<p>sdf</p>'
post_type   
u'post'
post_parent 
u''
csrfmiddlewaretoken 
u'4ec9ddf0bfa082ff8175394a155764c0'
menu_order  
u'0'
comment_status  
u'open'
FILES
No FILES data
COOKIES
Variable    Value
__utmz  
'50723647.1319781515.32.19.utmcsr=t.qq.com|utmccn=(referral)|utmcmd=referral|utm
cct=/gorf119'
sessionid   
'fea31100b48bc3bd87bf15ba070aec10'
csrftoken   
'4ec9ddf0bfa082ff8175394a155764c0'
__utma  
'50723647.168850695.1314772307.1320398550.1320746512.36'
__utmb  
'50723647.1.10.1320746519'
__utmc  
'50723647'
META
Variable    Value
wsgi.multiprocess   
False
HTTP_REFERER    
'http://test.gentoogle.com/admin/blog/post/add/'
REDIRECT_STATUS 
'200'
SERVER_SOFTWARE 
'lighttpd'
SCRIPT_NAME 
u''
REQUEST_METHOD  
'POST'
PATH_INFO   
u'/admin/blog/post/add/'
HTTP_ORIGIN 
'http://test.gentoogle.com'
SERVER_PROTOCOL 
'HTTP/1.1'
QUERY_STRING    
''
CONTENT_LENGTH  
'1198'
HTTP_ACCEPT_CHARSET 
'UTF-8,*;q=0.5'
HTTP_USER_AGENT 
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) 
Chrome/15.0.874.106 Safari/535.2'
HTTP_CONNECTION 
'keep-alive'
HTTP_COOKIE 
'__utma=100279579.356750814.1320288951.1320288951.1320746360.2; 
__utmb=100279579.1.10.1320746360; __utmc=100279579; 
__utmz=100279579.1320288951.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); 
sessionid=fea31100b48bc3bd87bf15ba070aec10; 
__utma=50723647.168850695.1314772307.1320398550.1320746512.36; 
__utmb=50723647.1.10.1320746519; __utmc=50723647; 
__utmz=50723647.1319781515.32.19.utmcsr=t.qq.com|utmccn=(referral)|utmcmd=referr
al|utmcct=/gorf119; csrftoken=4ec9ddf0bfa082ff8175394a155764c0'
SERVER_NAME 
'test.gentoogle.com'
REMOTE_PORT 
'37081'
wsgi.url_scheme 
'http'
PATH_TRANSLATED 
'/home/lq/pylogs//admin/blog/post/add/'
SERVER_PORT 
'80'
SERVER_ADDR 
'127.0.0.1'
DOCUMENT_ROOT   
'/home/lq/pylogs/'
CONTENT_TYPE    
'multipart/form-data; boundary=----WebKitFormBoundarymB2dYZBRkKgJKl63'
SCRIPT_FILENAME 
'/home/lq/pylogs/gentoogle.fcgi'
wsgi.input  
<flup.server.fcgi_base.InputStream object at 0x18c7e90>
HTTP_HOST   
'test.gentoogle.com'
wsgi.multithread    
True
HTTP_CACHE_CONTROL  
'max-age=0'
REQUEST_URI 
'/admin/blog/post/add/'
HTTP_ACCEPT 
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
wsgi.version    
(1, 0)
GATEWAY_INTERFACE   
'CGI/1.1'
wsgi.run_once   
False
wsgi.errors 
<flup.server.fcgi_base.TeeOutputStream object at 0x18ccd10>
REMOTE_ADDR 
'127.0.0.1'
HTTP_ACCEPT_LANGUAGE    
'zh-CN,zh;q=0.8'
REDIRECT_URI    
'/gentoogle.fcgi/admin/blog/post/add/'
HTTP_CONTENT_LENGTH 
'1198'
CSRF_COOKIE 
'4ec9ddf0bfa082ff8175394a155764c0'
HTTP_ACCEPT_ENCODING    
'gzip,deflate,sdch'
Settings
Using settings module pylogs.settings
Setting Value
USE_L10N    
False
USE_THOUSAND_SEPARATOR  
False
LANGUAGE_CODE   
'zh-cn'
ROOT_URLCONF    
'urls'
MANAGERS    
()
DEFAULT_CHARSET 
'utf-8'
STATIC_ROOT 
''
FEED_COPYRIGHT  
'Gorf\xe7\x9a\x84\xe6\x97\xa5\xe5\xa4\x8d\xe4\xb8\x80\xe6\x97\xa5emerge'
MESSAGE_STORAGE 
'django.contrib.messages.storage.user_messages.LegacyFallbackStorage'
DATABASE_HOST   
'localhost'
IGNORABLE_404_STARTS    
('/cgi-bin/', '/_vti_bin', '/_vti_inf')
SEND_BROKEN_LINK_EMAILS 
False
URL_VALIDATOR_USER_AGENT    
'Django/1.3.1 (http://www.djangoproject.com)'
STATICFILES_FINDERS 
('django.contrib.staticfiles.finders.FileSystemFinder',
 'django.contrib.staticfiles.finders.AppDirectoriesFinder')
SESSION_COOKIE_DOMAIN   
None
SESSION_COOKIE_NAME 
'sessionid'
VERSION 
(1, 15, 'beta')
COMMENTS_MODERATORS_GROUP   
None
TIME_INPUT_FORMATS  
('%H:%M:%S', '%H:%M')
DATABASES   
{'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2',
             'HOST': 'localhost',
             'NAME': 'pylogs',
             'OPTIONS': {},
             'PASSWORD': '********************',
             'PORT': '',
             'TEST_CHARSET': None,
             'TEST_COLLATION': None,
             'TEST_MIRROR': None,
             'TEST_NAME': None,
             'TIME_ZONE': 'Asia/Chongqing',
             'USER': 'blog'}}
TEST_DATABASE_NAME  
None
FILE_UPLOAD_PERMISSIONS 
None
FILE_UPLOAD_HANDLERS    
('django.core.files.uploadhandler.MemoryFileUploadHandler',
 'django.core.files.uploadhandler.TemporaryFileUploadHandler')
TEMPLATE_CONTEXT_PROCESSORS 
('django.contrib.auth.context_processors.auth',
 'django.core.context_processors.debug',
 'django.core.context_processors.i18n',
 'django.core.context_processors.media',
 'django.core.context_processors.static',
 'django.contrib.messages.context_processors.messages')
DEFAULT_CONTENT_TYPE    
'text/html'
APPEND_SLASH    
True
FIRST_DAY_OF_WEEK   
0
DATABASE_ROUTERS    
[]
YEAR_MONTH_FORMAT   
'F Y'
STATICFILES_STORAGE 
'django.contrib.staticfiles.storage.StaticFilesStorage'
CACHES  
{'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
             'LOCATION': ''}}
SERVER_EMAIL    
'root@localhost'
ALLOW_FILE_TYPES    
('.jpg', '.gif', '.png')
USE_X_FORWARDED_HOST    
False
IGNORABLE_404_ENDS  
('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')
MIDDLEWARE_CLASSES  
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')
USE_I18N    
True
THOUSAND_SEPARATOR  
','
SECRET_KEY  
'********************'
LANGUAGE_COOKIE_NAME    
'django_language'
FILE_UPLOAD_TEMP_DIR    
None
THEME_NAME  
'techicon'
TRANSACTIONS_MANAGED    
False
LOGGING_CONFIG  
'django.utils.log.dictConfig'
TEMPLATE_LOADERS    
('django.template.loaders.filesystem.load_template_source',
 'django.template.loaders.app_directories.load_template_source')
TEMPLATE_DEBUG  
True
AUTHENTICATION_BACKENDS 
('django.contrib.auth.backends.ModelBackend',)
TEST_DATABASE_COLLATION 
None
FORCE_SCRIPT_NAME   
''
CACHE_BACKEND   
'locmem://'
SESSION_COOKIE_SECURE   
False
CSRF_COOKIE_DOMAIN  
None
FILE_CHARSET    
'utf-8'
DEBUG   
True
SESSION_FILE_PATH   
None
DEFAULT_FILE_STORAGE    
'django.core.files.storage.FileSystemStorage'
INSTALLED_APPS  
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'blog',
 'todo',
 'filemanager',
 'wap']
LANGUAGES   
(('ar', 'Arabic'),
 ('az', 'Azerbaijani'),
 ('bg', 'Bulgarian'),
 ('bn', 'Bengali'),
 ('bs', 'Bosnian'),
 ('ca', 'Catalan'),
 ('cs', 'Czech'),
 ('cy', 'Welsh'),
 ('da', 'Danish'),
 ('de', 'German'),
 ('el', 'Greek'),
 ('en', 'English'),
 ('en-gb', 'British English'),
 ('es', 'Spanish'),
 ('es-ar', 'Argentinian Spanish'),
 ('es-mx', 'Mexican Spanish'),
 ('es-ni', 'Nicaraguan Spanish'),
 ('et', 'Estonian'),
 ('eu', 'Basque'),
 ('fa', 'Persian'),
 ('fi', 'Finnish'),
 ('fr', 'French'),
 ('fy-nl', 'Frisian'),
 ('ga', 'Irish'),
 ('gl', 'Galician'),
 ('he', 'Hebrew'),
 ('hi', 'Hindi'),
 ('hr', 'Croatian'),
 ('hu', 'Hungarian'),
 ('id', 'Indonesian'),
 ('is', 'Icelandic'),
 ('it', 'Italian'),
 ('ja', 'Japanese'),
 ('ka', 'Georgian'),
 ('km', 'Khmer'),
 ('kn', 'Kannada'),
 ('ko', 'Korean'),
 ('lt', 'Lithuanian'),
 ('lv', 'Latvian'),
 ('mk', 'Macedonian'),
 ('ml', 'Malayalam'),
 ('mn', 'Mongolian'),
 ('nl', 'Dutch'),
 ('no', 'Norwegian'),
 ('nb', 'Norwegian Bokmal'),
 ('nn', 'Norwegian Nynorsk'),
 ('pa', 'Punjabi'),
 ('pl', 'Polish'),
 ('pt', 'Portuguese'),
 ('pt-br', 'Brazilian Portuguese'),
 ('ro', 'Romanian'),
 ('ru', 'Russian'),
 ('sk', 'Slovak'),
 ('sl', 'Slovenian'),
 ('sq', 'Albanian'),
 ('sr', 'Serbian'),
 ('sr-latn', 'Serbian Latin'),
 ('sv', 'Swedish'),
 ('ta', 'Tamil'),
 ('te', 'Telugu'),
 ('th', 'Thai'),
 ('tr', 'Turkish'),
 ('uk', 'Ukrainian'),
 ('ur', 'Urdu'),
 ('vi', 'Vietnamese'),
 ('zh-cn', 'Simplified Chinese'),
 ('zh-tw', 'Traditional Chinese'))
DATABASE_ENGINE 
'postgresql_psycopg2'
DATABASE_NAME   
'pylogs'
COMMENTS_FIRST_FEW  
0
PREPEND_WWW 
False
TEST_DATABASE_CHARSET   
None
SESSION_COOKIE_HTTPONLY 
False
DATABASE_PORT   
''
DEBUG_PROPAGATE_EXCEPTIONS  
False
INTERNAL_IPS    
()
MONTH_DAY_FORMAT    
'F j'
LOGIN_URL   
'/accounts/login/'
SESSION_EXPIRE_AT_BROWSER_CLOSE 
False
SESSION_SAVE_EVERY_REQUEST  
False
TIME_FORMAT 
'P'
DATE_INPUT_FORMATS  
('%Y-%m-%d',
 '%m/%d/%Y',
 '%m/%d/%y',
 '%b %d %Y',
 '%b %d, %Y',
 '%d %b %Y',
 '%d %b, %Y',
 '%B %d %Y',
 '%B %d, %Y',
 '%d %B %Y',
 '%d %B, %Y')
CSRF_COOKIE_NAME    
'csrftoken'
EMAIL_HOST_PASSWORD 
'********************'
PASSWORD_RESET_TIMEOUT_DAYS 
'********************'
CACHE_MIDDLEWARE_ALIAS  
'default'
FEED_POST_AUTHOR_NAME   
'Gorf'
ADMIN_MEDIA_PREFIX  
'/admin_media/'
NUMBER_GROUPING 
0
SESSION_ENGINE  
'django.contrib.sessions.backends.db'
CSRF_FAILURE_VIEW   
'django.views.csrf.csrf_failure'
COMMENTS_SKETCHY_USERS_GROUP    
None
LOGIN_REDIRECT_URL  
'/accounts/profile/'
SESSION_COOKIE_PATH 
'/'
LOGGING 
{'disable_existing_loggers': False,
 'handlers': {'mail_admins': {'class': 'django.utils.log.AdminEmailHandler',
                              'level': 'ERROR'}},
 'loggers': {'django.request': {'handlers': ['mail_admins'],
                                'level': 'ERROR',
                                'propagate': True}},
 'version': 1}
CACHE_MIDDLEWARE_KEY_PREFIX 
''
FEED_BLOG_URL_PREFIX    
'http://gentoogle.com/'
LOCALE_PATHS    
()
TEMPLATE_STRING_IF_INVALID  
''
COMMENTS_ALLOW_PROFANITIES  
False
LOGOUT_URL  
'/accounts/logout/'
EMAIL_USE_TLS   
True
TEMPLATE_DIRS   
('/home/lq/pylogs/../pylogs/templates',)
FIXTURE_DIRS    
()
EMAIL_HOST  
'smtp.gmail.com'
DATE_FORMAT 
'N j, Y'
MEDIA_ROOT  
'/home/lq/pylogs/../pylogs/media'
ADMINS  
()
FORMAT_MODULE_PATH  
None
DEFAULT_FROM_EMAIL  
'webmaster@localhost'
STATICFILES_DIRS    
()
MEDIA_URL   
'/media'
DATETIME_FORMAT 
'N j, Y, P'
EMAIL_SUBJECT_PREFIX    
'[Django] '
SITE_ID 
1
DISALLOWED_USER_AGENTS  
()
ALLOWED_INCLUDE_ROOTS   
()
DECIMAL_SEPARATOR   
'.'
SHORT_DATE_FORMAT   
'm/d/Y'
DATABASE_USER   
'blog'
TEST_RUNNER 
'django.test.simple.DjangoTestSuiteRunner'
TIME_ZONE   
'Asia/Chongqing'
FILE_UPLOAD_MAX_MEMORY_SIZE 
2621440
EMAIL_BACKEND   
'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_TABLESPACE  
''
STATIC_PATH 
'./media'
SESSION_COOKIE_AGE  
1209600
SETTINGS_MODULE 
'pylogs.settings'
USE_ETAGS   
False
LANGUAGES_BIDI  
('he', 'ar', 'fa')
DEFAULT_INDEX_TABLESPACE    
''
FEED_GLOBAL_TITLE   
'Gorf \xe7\x9a\x84\xe6\x97\xa5\xe5\xa4\x8d\xe4\xb8\x80\xe6\x97\xa5Emerge: 
\xe6\x9c\x80\xe6\x96\xb0\xe6\x96\x87\xe7\xab\xa0'
STATIC_URL  
None
EMAIL_PORT  
25
SHORT_DATETIME_FORMAT   
'm/d/Y P'
FEED_GLOBAL_DESCRIPTION 
'\xe8\xae\xb0\xe5\xbd\x95\xe4\xbd\xa0\xe7\x9a\x84\xe7\x94\x9f\xe6\xb4\xbb\xe2\x8
0\xa6\xe2\x80\xa6'
ABSOLUTE_URL_OVERRIDES  
{}
DATABASE_OPTIONS    
{}
CACHE_MIDDLEWARE_SECONDS    
600
BANNED_IPS  
()
DATETIME_INPUT_FORMATS  
('%Y-%m-%d %H:%M:%S',
 '%Y-%m-%d %H:%M',
 '%Y-%m-%d',
 '%m/%d/%Y %H:%M:%S',
 '%m/%d/%Y %H:%M',
 '%m/%d/%Y',
 '%m/%d/%y %H:%M:%S',
 '%m/%d/%y %H:%M',
 '%m/%d/%y')
DATABASE_PASSWORD   
'********************'
ADMIN_FOR   
()
PROFANITIES_LIST    
'********************'
EMAIL_HOST_USER 
'qingyuan.liu@gmail.com'
COMMENTS_BANNED_USERS_GROUP 
None
You're seeing this error because you have DEBUG = True in your Django settings 
file. Change that to False, and Django will display a standard 500 page.

Original issue reported on code.google.com by liuqing....@gmail.com on 8 Nov 2011 at 10:46

GoogleCodeExporter commented 9 years ago
ALTER SEQUENCE blog_post_id_seq OWNED BY blog_post.id;
可解决。
参见:
http://stackoverflow.com/questions/6412962/django-admin-instance-needs-to-have-a
-primary-key-value-before-a-many-to-many
https://code.djangoproject.com/ticket/13295
https://code.djangoproject.com/ticket/13179
https://code.djangoproject.com/ticket/15682
http://stackoverflow.com/questions/6466836/postgres-sequences-without-an-owned-b
y-attribute-do-not-return-an-id-in-django
http://stackoverflow.com/questions/6090859/django-instance-needs-to-have-a-prima
ry-key-value-before-a-many-to-many-relatio

Original comment by liuqing....@gmail.com on 30 Nov 2011 at 7:47

GoogleCodeExporter commented 9 years ago
pylogs=# ALTER SEQUENCE blog_category_id_seq OWNED BY blog_category.id
pylogs-# ALTER SEQUENCE blog_post_category_id_seq OWNED BY blog_post_category.id
这两条也要加,要不然分类不正常

Original comment by liuqing....@gmail.com on 9 Mar 2012 at 2:54