1
votes

I am just starting out to develop a Django Blog, and am following this youtube tutorial - https://www.youtube.com/watch?v=7rgph8en0Jc&spfreload=1

I am using Django 1.6.6.

  1. Everytime I try to add Entry in Admin, I get this error. Thanks for your help!

Environment:

Django Version: 1.6.6 Python Version: 2.7.8 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'niceblog', 'django_markdown') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback:
File "C:\Users\user\desktop\firstblog\lib\site-packages\django\core\handlers\base.py"

in get_response 112. response = wrapped_callback(request, *callback_args, >**callback_kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\options.py" in wrapper 450. return self.admin_site.admin_view(view)(*args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py" in _wrapped_view 99. response = view_func(request, *args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func 52. response = view_func(request, *args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\sites.py" in inner 198. return view(request, *args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py" in _wrapper 29. return bound_func(*args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py" in _wrapped_view 99. response = view_func(request, *args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py" in bound_func 25. return func(self, *args2, **kwargs2) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\transaction.py" in inner 371. return func(*args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\options.py" in add_view 1149. self.save_model(request, new_object, form, False) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\options.py" in save_model 878. obj.save() File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\base.py" in save 545. force_update=force_update, update_fields=update_fields) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\base.py" in save_base 573. updated = self._save_table(raw, cls, force_insert, force_update, using, >update_fields) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\base.py" in _save_table 654. result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\base.py" in _do_insert 687. using=using, raw=raw) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\manager.py" in _insert 232. return insert_query(self.model, objs, fields, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\query.py" in insert_query 1514. return query.get_compiler(using=using).execute_sql(return_id) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql 903. cursor.execute(sql, params) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\util.py" in execute 69. return super(CursorDebugWrapper, self).execute(sql, params) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\util.py" in execute 53. return self.cursor.execute(sql, params) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\utils.py" in exit 99. six.reraise(dj_exc_type, dj_exc_value, traceback) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\util.py" in execute 53. return self.cursor.execute(sql, params) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\sqlite3\base.py" in execute 452. return Database.Cursor.execute(self, query, params)

Exception Type: IntegrityError at /admin/niceblog/entry/add/
Exception Value: niceblog_entry.slug may not be NULL
  1. Everytime I try to edit Entry in Admin, it throws this error

Environment:

Django Version: 1.6.6 Python Version: 2.7.8 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'niceblog', 'django_markdown') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback: File "C:\Users\user\desktop\firstblog\lib\site-packages\django\core\handlers\base.py" in get_response 112. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\options.py" in wrapper 450. return self.admin_site.admin_view(view)(*args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py" in _wrapped_view 99. response = view_func(request, *args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func 52. response = view_func(request, *args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\sites.py" in inner 198. return view(request, *args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py" in _wrapper 29. return bound_func(*args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py" in _wrapped_view 99. response = view_func(request, *args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\utils\decorators.py" in bound_func 25. return func(self, *args2, **kwargs2) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\transaction.py" in inner 371. return func(*args, **kwargs) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\contrib\admin\options.py" in change_view 1255. form = ModelForm(instance=obj) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\forms\models.py" in init 315. object_data = model_to_dict(instance, opts.fields, opts.exclude) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\forms\models.py" in model_to_dict 141. data[f.name] = list(f.value_from_object(instance).values_list('pk', flat=True)) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\query.py" in iter 96. self._fetch_all() File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\query.py" in _fetch_all 857. self._result_cache = list(self.iterator()) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\query.py" in iterator 1068. for row in self.query.get_compiler(self.db).results_iter(): File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\sql\compiler.py" in results_iter 713. for rows in self.execute_sql(MULTI): File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql 786. cursor.execute(sql, params) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\util.py" in execute 69. return super(CursorDebugWrapper, self).execute(sql, params) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\util.py" in execute 53. return self.cursor.execute(sql, params) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\utils.py" in exit 99. six.reraise(dj_exc_type, dj_exc_value, traceback) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\util.py" in execute 53. return self.cursor.execute(sql, params) File "C:\Users\user\desktop\firstblog\lib\site-packages\django\db\backends\sqlite3\base.py" in execute 452. return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /admin/niceblog/entry/2/ Exception Value: no such table: niceblog_entry_tags

models.py file --->

class Tag(models.Model):
    slug = models.SlugField(max_length=200, unique=True)

def __unicode__(self):
    return self.slug

class Entry(models.Model):
    title = models.CharField(max_length=200)
    body = models.TextField()
    publish = models.BooleanField(default=True)
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)
    tags = models.ManyToManyField(Tag)

    def __unicode__(self):
        return self.title

    class Meta:
        verbose_name = "Blog Entry"
        verbose_name_plural = "Blog Entries"
        ordering = ['-created']

admin.py file --->

class EntryAdmin(MarkdownModelAdmin):
    list_display = ("title", "created")

admin.site.register(Entry, EntryAdmin) 
admin.site.register(Tag)
1
You haven't synced/migrated your database properly.Henrik Andersson
i tried the usual python manage.py syncdb a couple of times. checked the table with python manage.py sql as well. somehow 'tag' is not appearing under the entry table.codemax
@codemax Drop all your tables (if you are doing this for practice), delete all the migrations and create one initial migration. python manage.py schemamigration <app_name> --initNagkumar Arkalgud
hi, i don't have schemamigration in my manage.py. but i dropped my table and deleted migrationscodemax
i found it by adding it in my settings.py filecodemax

1 Answers

1
votes

I guess, Entry.tags was added after table creation. If it's possible to upgrade django to 1.7 then you can use built-in migrations. Firstable reset your app to actual db schema, i.e. remove tags field, then:

# Create initial migrations
$ python manage.py makemigrations your_app
# Migrate
$ python manage.py migrate your_app
# Add your tags field. Repeat
$ python manage.py makemigrations your_app
$ python manage.py migrate your_app

If you want to stay on django 1.6, use South. It's pretty much the same:

# Create initial migrations
$ python manage.py schemamigration your_app intial --init
# Migrate
$ python manage.py migrate your_app --fake
# Add your tags field. Create migration
$ python manage.py schemamigration your_app add_tags --auto
$ python manage.py migrate your_app