English 中文(简体)
Django - Database 错误: 无
原标题:Django - DatabaseError: No such table

我界定了两种模式:

class Server(models.Model):
    owners = models.ManyToManyField( Person )

class Person(models.Model):
    name = models.CharField(max_length=50)

admin.site.register(Server)
admin.site.register(Person)

之后,我甚至检查了 s,只是为了 f:

BEGIN;
CREATE TABLE "servers_server_owners" (
    "id" integer NOT NULL PRIMARY KEY,
    "server_id" integer NOT NULL,
    "person_id" integer NOT NULL,
    UNIQUE ("server_id", "person_id")
)
;
CREATE TABLE "servers_server" (
    "id" integer NOT NULL PRIMARY KEY,
    "name" varchar(50) NOT NULL,
    "port" integer unsigned NOT NULL,
    "state" integer NOT NULL
)
;
CREATE TABLE "servers_person" (
    "id" integer NOT NULL PRIMARY KEY,
    "name" varchar(50) NOT NULL
)
;
COMMIT;

甚至有<条码>。

我在<代码>syncdb上安装了数据库的新模型。 我去了行政接口,以界定一些玩物,但我有以下错误:

DatabaseError at /admin/servers/server/1/  
no such table: servers_server_owners

我关闭了DC-server, 运行syncdb,再次启用服务器: 还有一个同样的问题。 为什么会失败,尽管我刚才告诉我,这还是产生了id?

最佳回答

事实上,问题是,这个表永远不会产生。 页: 1 我用django略为新鲜,我不知道/manage.py syncdb没有更新现有的模型,而只是创造不存在的模式。

由于该模型服务器在我添加了另一个模型之前就已存在,而且该模型已经安装在db中,因此Syncdb实际上没有创建新的表格。

问题回答

展望未来,见-South,这对应用你对数据库的模型变化非常有用,不必每当你改变模型时建立一个新的数据库。

With it you can easily: python manage.py migrate app_name and South will write your model changes. The documentation is pretty straightforward.

I meet the same problem today and fix it. I think you miss some command in tutorial 1. just do follow:

./python manage.py makemigrations polls
python manage.py sql polls
./python manage.py syncdb

then fix it and gain the table polls and you can see the table created. you should read the manage.py makemigrations command.

for django 1.9, this is what i did and it solved the issue.

python manage.py makemigrations app_name

python管理。 迁徙

  1. use "manage.py help" to check the command
  2. if you find migrate and makemigration, it means your python has updated

步骤1:

python manage.py makemigration

结果1:

Migrations for  mainsite :
mainsitemigrations001_initial.py
- Create model Post

步骤2:

python manage.py migrate

结果2:

Operations to perform:
Apply all migrations: admin, auth, contenttypes, mainsite, sessions
Running migrations:
Applying mainsite.0001_initial... OK

最后,执业者。 Done





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签