django admin中的操作错误,没有这样的表

时间:2017-06-07 12:34:05

标签: django django-admin

我是django的新手。我运行命令

manage.py makemigrations api
manage.py sqlmigrate api 0001
manage.py migrate

其中api是我的应用程序的名称。看起来迁移是成功的,因为我没有得到任何错误,但当我路由到管理面板(默认)。 现在,当我选择任何型号名称时,它会产生如下错误。 以下是显示的错误:

  

/ admin / api / donation /

中的OperationalError      

没有这样的表:api_donation

     

请求方法:GET请求URL:     http://127.0.0.1:8000/admin/api/donation/ Django版本:1.11.1   异常类型:OperationalError异常值:

     

没有这样的表:api_donation

     

例外位置:     /usr/local/lib/python3.5/dist-packages/django/db/backends/sqlite3/base.py   在执行中,第328行Python可执行文件:/ usr / bin / python3 Python   版本:3.5.2 Python路径:

     

[' / home / kdpisda / Projects / creekside',' /usr/lib/python35.zip',   ' /usr/lib/python3.5' ;,' /usr/lib/python3.5/plat-x86_64-linux-gnu',   ' /usr/lib/python3.5/lib-dynload' ;,   ' /usr/local/lib/python3.5/dist-packages' ;,   ' / usr / lib中/ python3 / DIST-包']

     

服务器时间:2017年6月7日星期三12:21:51 +0000

追溯:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/api/donation/

Django Version: 1.11.1
Python Version: 3.5.2
Installed Applications:
['dashboard',
 'login',
 'api',
 'aboutus',
 'contactus',
 'ourprogram',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 '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 "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py" in execute
  65.                 return self.cursor.execute(sql, params)

File "/usr/local/lib/python3.5/dist-packages/django/db/backends/sqlite3/base.py" in execute
  328.         return Database.Cursor.execute(self, query, params)

The above exception (no such table: api_donation) was the direct cause of the following exception:

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.5/dist-packages/django/contrib/admin/options.py" in wrapper
  551.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "/usr/local/lib/python3.5/dist-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "/usr/local/lib/python3.5/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)

File "/usr/local/lib/python3.5/dist-packages/django/contrib/admin/sites.py" in inner
  224.             return view(request, *args, **kwargs)

File "/usr/local/lib/python3.5/dist-packages/django/utils/decorators.py" in _wrapper
  67.             return bound_func(*args, **kwargs)

File "/usr/local/lib/python3.5/dist-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "/usr/local/lib/python3.5/dist-packages/django/utils/decorators.py" in bound_func
  63.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "/usr/local/lib/python3.5/dist-packages/django/contrib/admin/options.py" in changelist_view
  1542.                 self.list_max_show_all, self.list_editable, self,

File "/usr/local/lib/python3.5/dist-packages/django/contrib/admin/views/main.py" in __init__
  79.         self.get_results(request)

File "/usr/local/lib/python3.5/dist-packages/django/contrib/admin/views/main.py" in get_results
  177.         result_count = paginator.count

File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py" in __get__
  35.         res = instance.__dict__[self.name] = self.func(instance)

File "/usr/local/lib/python3.5/dist-packages/django/core/paginator.py" in count
  79.             return self.object_list.count()

File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py" in count
  364.         return self.query.get_count(using=self.db)

File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/query.py" in get_count
  499.         number = obj.get_aggregation(using, ['__count'])['__count']

File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/query.py" in get_aggregation
  480.         result = compiler.execute_sql(SINGLE)

File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/compiler.py" in execute_sql
  886.             raise original_exception

File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/compiler.py" in execute_sql
  876.             cursor.execute(sql, params)

File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py" in execute
  80.             return super(CursorDebugWrapper, self).execute(sql, params)

File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py" in execute
  65.                 return self.cursor.execute(sql, params)

File "/usr/local/lib/python3.5/dist-packages/django/db/utils.py" in __exit__
  94.                 six.reraise(dj_exc_type, dj_exc_value, traceback)

File "/usr/local/lib/python3.5/dist-packages/django/utils/six.py" in reraise
  685.             raise value.with_traceback(tb)

File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py" in execute
  65.                 return self.cursor.execute(sql, params)

File "/usr/local/lib/python3.5/dist-packages/django/db/backends/sqlite3/base.py" in execute
  328.         return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /admin/api/donation/
Exception Value: no such table: api_donation

manage.py输出sqlmigrate api 0001

BEGIN;
--
-- Create model Donation
--
CREATE TABLE "api_donation" ("donation_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "amount" integer NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL);
--
-- Create model Grade
--
CREATE TABLE "api_grade" ("grade_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(32) NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL);
--
-- Create model Invite
--
CREATE TABLE "api_invite" ("invite_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "invited_to" varchar(32) NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL);
--
-- Create model Program
--
CREATE TABLE "api_program" ("program_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(60) NOT NULL, "opened_on" datetime NOT NULL, "valid_till" datetime NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL);
--
-- Create model School
--
CREATE TABLE "api_school" ("school_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(50) NOT NULL, "school_zip" integer NOT NULL, "email" varchar(32) NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL);
--
-- Create model Student
--
CREATE TABLE "api_student" ("student_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "first_name" varchar(32) NOT NULL, "last_name" varchar(32) NOT NULL, "collected_amount" integer NOT NULL, "profile_pic" varchar(100) NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL);
--
-- Create model Teacher
--
CREATE TABLE "api_teacher" ("teacher_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(64) NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL, "grade_id" integer NOT NULL REFERENCES "api_grade" ("grade_id"));
--
-- Create model Transaction
--
CREATE TABLE "api_transaction" ("transaction_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "amount" integer NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL, "invite_id" integer NOT NULL REFERENCES "api_invite" ("invite_id"));
--
-- Create model User
--
CREATE TABLE "api_user" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "parent_name" varchar(60) NOT NULL, "password" varchar(500) NOT NULL, "email" varchar(32) NOT NULL, "status" varchar(2) NOT NULL, "uniqueKey" char(32) NOT NULL UNIQUE, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL);
--
-- Add field added_by to student
--
ALTER TABLE "api_student" RENAME TO "api_student__old";
CREATE TABLE "api_student" ("student_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "first_name" varchar(32) NOT NULL, "last_name" varchar(32) NOT NULL, "collected_amount" integer NOT NULL, "profile_pic" varchar(100) NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL, "added_by_id" integer NOT NULL REFERENCES "api_user" ("id"));
INSERT INTO "api_student" ("last_name", "added_by_id", "student_id", "modified_at", "created_at", "collected_amount", "profile_pic", "first_name") SELECT "last_name", NULL, "student_id", "modified_at", "created_at", "collected_amount", "profile_pic", "first_name" FROM "api_student__old";
DROP TABLE "api_student__old";
CREATE INDEX "api_teacher_grade_id_211af16f" ON "api_teacher" ("grade_id");
CREATE INDEX "api_transaction_invite_id_9bb6bf71" ON "api_transaction" ("invite_id");
CREATE INDEX "api_student_added_by_id_1ad331bf" ON "api_student" ("added_by_id");
--
-- Add field school to student
--
ALTER TABLE "api_student" RENAME TO "api_student__old";
CREATE TABLE "api_student" ("student_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "first_name" varchar(32) NOT NULL, "last_name" varchar(32) NOT NULL, "collected_amount" integer NOT NULL, "profile_pic" varchar(100) NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL, "added_by_id" integer NOT NULL REFERENCES "api_user" ("id"), "school_id" integer NOT NULL REFERENCES "api_school" ("school_id"));
INSERT INTO "api_student" ("last_name", "added_by_id", "school_id", "student_id", "modified_at", "created_at", "collected_amount", "profile_pic", "first_name") SELECT "last_name", "added_by_id", NULL, "student_id", "modified_at", "created_at", "collected_amount", "profile_pic", "first_name" FROM "api_student__old";
DROP TABLE "api_student__old";
CREATE INDEX "api_student_added_by_id_1ad331bf" ON "api_student" ("added_by_id");
CREATE INDEX "api_student_school_id_fadda2f7" ON "api_student" ("school_id");
--
-- Add field invited_by to invite
--
ALTER TABLE "api_invite" RENAME TO "api_invite__old";
CREATE TABLE "api_invite" ("invite_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "invited_to" varchar(32) NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL, "invited_by_id" integer NOT NULL REFERENCES "api_user" ("id"));
INSERT INTO "api_invite" ("invite_id", "modified_at", "invited_by_id", "created_at", "invited_to") SELECT "invite_id", "modified_at", NULL, "created_at", "invited_to" FROM "api_invite__old";
DROP TABLE "api_invite__old";
CREATE INDEX "api_invite_invited_by_id_7e70c389" ON "api_invite" ("invited_by_id");
--
-- Add field invited_for to invite
--
ALTER TABLE "api_invite" RENAME TO "api_invite__old";
CREATE TABLE "api_invite" ("invite_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "invited_to" varchar(32) NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL, "invited_by_id" integer NOT NULL REFERENCES "api_user" ("id"), "invited_for_id" integer NOT NULL REFERENCES "api_student" ("student_id"));
INSERT INTO "api_invite" ("modified_at", "invited_to", "invite_id", "created_at", "invited_by_id", "invited_for_id") SELECT "modified_at", "invited_to", "invite_id", "created_at", "invited_by_id", NULL FROM "api_invite__old";
DROP TABLE "api_invite__old";
CREATE INDEX "api_invite_invited_by_id_7e70c389" ON "api_invite" ("invited_by_id");
CREATE INDEX "api_invite_invited_for_id_f9bf56c6" ON "api_invite" ("invited_for_id");
--
-- Add field program to invite
--
ALTER TABLE "api_invite" RENAME TO "api_invite__old";
CREATE TABLE "api_invite" ("invite_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "invited_to" varchar(32) NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL, "invited_by_id" integer NOT NULL REFERENCES "api_user" ("id"), "invited_for_id" integer NOT NULL REFERENCES "api_student" ("student_id"), "program_id" integer NOT NULL REFERENCES "api_program" ("program_id"));
INSERT INTO "api_invite" ("modified_at", "invited_to", "invite_id", "created_at", "invited_by_id", "invited_for_id", "program_id") SELECT "modified_at", "invited_to", "invite_id", "created_at", "invited_by_id", "invited_for_id", NULL FROM "api_invite__old";
DROP TABLE "api_invite__old";
CREATE INDEX "api_invite_invited_by_id_7e70c389" ON "api_invite" ("invited_by_id");
CREATE INDEX "api_invite_invited_for_id_f9bf56c6" ON "api_invite" ("invited_for_id");
CREATE INDEX "api_invite_program_id_be19626b" ON "api_invite" ("program_id");
--
-- Add field invite to donation
--
ALTER TABLE "api_donation" RENAME TO "api_donation__old";
CREATE TABLE "api_donation" ("donation_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "amount" integer NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL, "invite_id" integer NOT NULL REFERENCES "api_invite" ("invite_id"));
INSERT INTO "api_donation" ("donation_id", "modified_at", "invite_id", "created_at", "amount") SELECT "donation_id", "modified_at", NULL, "created_at", "amount" FROM "api_donation__old";
DROP TABLE "api_donation__old";
CREATE INDEX "api_donation_invite_id_6eb11ccd" ON "api_donation" ("invite_id");
--
-- Add field transaction to donation
--
ALTER TABLE "api_donation" RENAME TO "api_donation__old";
CREATE TABLE "api_donation" ("donation_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "amount" integer NOT NULL, "created_at" datetime NOT NULL, "modified_at" datetime NOT NULL, "invite_id" integer NOT NULL REFERENCES "api_invite" ("invite_id"), "transaction_id" integer NOT NULL REFERENCES "api_transaction" ("transaction_id"));
INSERT INTO "api_donation" ("invite_id", "modified_at", "amount", "donation_id", "created_at", "transaction_id") SELECT "invite_id", "modified_at", "amount", "donation_id", "created_at", NULL FROM "api_donation__old";
DROP TABLE "api_donation__old";
CREATE INDEX "api_donation_invite_id_6eb11ccd" ON "api_donation" ("invite_id");
CREATE INDEX "api_donation_transaction_id_915e48ae" ON "api_donation" ("transaction_id");
COMMIT;
模特捐赠

class Donation(models.Model):
    donation_id = models.AutoField(primary_key=True)
    invite = models.ForeignKey('Invite', on_delete=models.CASCADE)
    amount = models.IntegerField(null=False)
    transaction = models.ForeignKey('Transaction', on_delete=models.CASCADE,)
    created_at = models.DateTimeField(auto_now_add=True, editable=False, null=False, blank=False)
    modified_at = models.DateTimeField(auto_now=True, editable=False, null=False, blank=False)
    def __str__(self):
        return self.donation_id

请帮忙做什么。

0 个答案:

没有答案