标签: django-south

Django south:在数据迁移中改变字段类型

我是从更改字段CharFieldIntegerField.字段名称保持不变.新创建的字段将基于旧字段.例如,如果旧字段是"L",则它将具有数字"1".我怎样才能在forwards()功能中实现这一目标?

django django-south

15
推荐指数
1
解决办法
4722
查看次数

从django.db导入模型,迁移ImportError:无法导入名称迁移

所以我开始在我的Django Web服务器上遇到南方的一些问题.每次使用此输出迁移命令失败:

from django.db import models, migrations

ImportError: cannot import name migrations 
Run Code Online (Sandbox Code Playgroud)

(在此之上,错误显示无法迁移的文件的路径)

我的Django版本是1.5.1,而我的南版本是0.8.4

让我最烦恼的是模块django.db.migrations无处可寻.

有任何想法吗?

python django migrate django-south

15
推荐指数
1
解决办法
1万
查看次数

如何在南迁移中访问auth用户的User.objects.create_user(...)?

我没有使用django的auth模块,而是使用了我自己的模块而且已经后悔了很多.

为了纠正这种情况,我正在尝试将数据从我的用户模型迁移到django.auth.models.User.

我创建了一个数据迁移,如下所示:

def forwards(self, orm):
    """Migrate user information from mooi User model to auth User model."""

    OldUser = orm['mooi.User']
    User = orm['auth.User']
    Profile = orm['mooi.Profile']

    oldUsers = OldUser.objects.all()
    for oldUser in oldUsers:
        newUser = User.objects.create_user(username=oldUser.id, email=oldUser.email, password=oldUser.password)
        # ...more irrelevant code follows...
Run Code Online (Sandbox Code Playgroud)

当我运行迁移时,我收到此错误(追溯):

#...irrelevant traceback precedes...
File "[projdir]/mooi/migrations/0005_from_mooi_users_create_auth_users_with_profiles.py", line 18, in forwards
    newUser = User.objects.create_user(username=oldUser.id, email=oldUser.email, password=oldUser.password)
  File "[virtual_env_dir]lib/python2.6/site-packages/south/orm.py", line 397, in __getattr__
    return getattr(self.real, name)
AttributeError: 'Manager' object has no attribute 'create_user'
Run Code Online (Sandbox Code Playgroud)

经过进一步调查,我发现Manager所提到的是时间south.orm.NoDryRunManager,这解释了错误.

现在,我甚至需要的原因 …

migration django django-authentication django-south

14
推荐指数
2
解决办法
5834
查看次数

在django字段中添加"直通"表并与南方迁移?

看起来这应该是"容易"或至少在某处记录,我只是无法找到它.

让我们说我有一个模型:

class A(models.Model):
    users = models.ManyToMany('auth.User', blank=True)
Run Code Online (Sandbox Code Playgroud)

现在我想迁移到一个through表来向ManyToMany关系添加字段...

class AUsers(models.Model):
    user = models.ForeignKey('auth.User')
    a = models.ForeignKey('A')
    new_field = models.BooleanField()

class A(models.Model):
    users = models.ManyToMany('auth.User', blank=True, through='AUsers')
Run Code Online (Sandbox Code Playgroud)

然后我做:

% ./manage.py schemamigration app --auto
Run Code Online (Sandbox Code Playgroud)

并不奇怪,它告诉我它将通过表删除原始的自动创建并为其创建一个新的AUsers.目前最好的做法是什么?是否有适当的方式迁移到新through表?我db_table在Meta 使用吗?我是不是through=...马上使用...然后做一个schemamigration --auto,然后a datamigration复制当前表(不知何故,不确定...)然后添加through关系,让它杀死表?

这里的诀窍是什么?这真的很难吗?

django django-south

14
推荐指数
2
解决办法
2693
查看次数

Django syncdb和迁移

我正在将django网站从一个服务器移动到另一个服务器,我尝试了syncdb,所以我放了python manage.py syncdb,我得到了这个输出:

Syncing...
Creating tables ...
The following content types are stale and need to be deleted:

    orders | ordercontact

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel: no
Installing custom SQL ...
Installing indexes ...
No fixtures found.

Synced:
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > …
Run Code Online (Sandbox Code Playgroud)

django syncdb django-south

14
推荐指数
3
解决办法
3万
查看次数

Django South迁移到不同的数据库

南荣誉数据库路由器?我设置路由器将某些应用程序路由到一个数据库,将所有其他应用程序路由到默认数据库.我甚至确保南迁移历史表在两个DB中.但我无法让South只在相应的数据库中应用迁移.即使我使用--database向南运行,它也会将所有迁移应用于我指定的数据库,而不仅仅是从应该转到该数据库的应用程序迁移.

救命!谢谢.

django django-south

14
推荐指数
1
解决办法
2042
查看次数

找不到名为"X"的夹具

我正在使用Django 1.6,我使用South来处理迁移.在我的大多数应用程序中,我曾经有过initial_data.json文件.我将它们转换为加载迁移而不是Django自动加载(因为这在文档中是推荐的)

当我遇到一个奇怪的行为/错误,根据模型代码而不是迁移状态完成加载装置时,我使用的是南方版本0.8.2.我看到最新版本(0.8.4)已经添加了一些相关的bug修复loaddata,所以我升级到它.

现在我在加载夹具的所有迁移中收到以下错误:

UserWarning: No fixture named 'X' found. 
Run Code Online (Sandbox Code Playgroud)

当我使用Django时loaddata它工作正常.关于如何解决这个问题的任何想法?

django django-south

14
推荐指数
1
解决办法
7525
查看次数

使用South在Djoku上设置Django的麻烦 - 继续得到ProgrammingError:关系不存在

这就是我一直在做的事情:

本地 - 我有一个全新的postgres数据库,以及来自两个不同应用程序的两个models.py文件:

python manage.py syncdb
python manage.py schemamigration api --initial
python manage.py schemamigration extapi --initial
python manage.py migrate api 0001 --fake
python manage.py migrate extapi 0001 --fake
Run Code Online (Sandbox Code Playgroud)

这工作膨胀,我可以添加到数据库的东西就好了.

然后,当推送到Heroku时,我已经创建了一个空的应用程序:

git add .
git commit -m "Ready to go to Heroku"
git push heroku master
heroku run python manage.py syncdb
Run Code Online (Sandbox Code Playgroud)

这输出:

Running `python manage.py syncdb` attached to terminal... up, run.9548
Syncing...
Creating tables ...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups …
Run Code Online (Sandbox Code Playgroud)

django postgresql heroku django-south

14
推荐指数
1
解决办法
1万
查看次数

Django - 按CharField值长度过滤查询集

鉴于我有一个基于CharFieldor CharField的模型字段的遗留模型,如:

class MyModel(models.Model):
    name = models.CharField(max_length=1024, ...)
    ...
Run Code Online (Sandbox Code Playgroud)

我需要进行迁移以使其具有max_length最大值.255.首先,我正在编写一个datamigration使任何超过255个字符的值适应即将到来schemamigration的修复列的最大长度,我将在此工作后立即执行.

问题是我有一个非常大的数据集,我知道并非所有行都包含超过255个字符的值MyModel.name,我想考虑我的迁移只有那些人.

是否有任何方法(使用)django ORM仅过滤满足此条件的对象?就像是:

MyModel.objects.filter(name__len__gte=255)
Run Code Online (Sandbox Code Playgroud)

会很棒,但我相信这是不可能的,或者至少它不是那么简单.

有人知道完成此查询的任何方法吗?

谢谢!

python django data-migration django-south

14
推荐指数
2
解决办法
4969
查看次数

您的数据库没有南数据库模块'south.db.postgresql_psycopg2'

我是django的新手,我从南方得到这个错误,但我不知道我错过了什么.我搜索答案但我找不到任何东西.

There is no South database module 'south.db.postgresql_psycopg2' for your database. Please either choose a supported database, check for SOUTH_DATABASE_ADAPTER[S] settings, or remove South from INSTALLED_APPS.
Run Code Online (Sandbox Code Playgroud)

这是我的base_settings:

from unipath import Path

BASE_DIR = Path(__file__).ancestor(3)


SECRET_KEY = 'pp@iz7%bc7%+*11%usf7o@_e&)r2o&^3%zjse)n=6b&w^hem96'

DJANGO_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

)

THIRD_PARTY_APPS = (
    'south',

)

LOCAL_APPS = (


)


INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS


MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'misite.urls'

WSGI_APPLICATION = …
Run Code Online (Sandbox Code Playgroud)

python django django-south

14
推荐指数
4
解决办法
2万
查看次数