English 中文(简体)
在现有模式中添加与南达詹戈的自动加固领域?
原标题:Adding Autoincrement field to existing model with Django South?

我有一个Django项目,开始输入遗产数据库。 因此,有一个具有综合主要钥匙的模式。 只要我只使用遗留数据,但我现在要补充新的数据,而我所创造的形式告诉我,我正试图插入重复数据,大概是因为它只是把一个领域视为首要关键。

Now I want to change the model to use an autoincrement primary key, like one Django would automatically add. I tried removing the primary key attributes from the fields and putting them in unique_together in the Meta inner class. When I ran schemamigration with South, it wanted to add an id field as expected, but it asked for a default value.

我怎么能具体指出,南方应当以某种方式分配独特的钥匙,这对一个汽车加油场来说是合理的? (一) 将顺序[1.n]分配给某些任意记录顺序

If this is impossible is there another way to accomplish the same thing, preferably using Django and South?

问题回答

我解决了需要我做这项工作的问题:

I copied the data from the original table into a temporary table in SQL with INSERT INTO... SELECT.... I then deleted the original table and recreated it with the autoincrement field. Then I copied the data back into the new table, with the autoincrement values added automatically by the INSERT command. Finally I executed a fake run of the South migration to make South s tables consistent with the new schema.





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签