小编Jon*_*bop的帖子

Django迁移错误:您无法更改M2M字段或从M2M字段更改,或在M2M字段上添加或删除

我正在尝试将M2M字段修改为ForeignKey字段.命令validate显示没有问题,当我运行syncdb时:

ValueError: Cannot alter field xxx into yyy they are not compatible types (you cannot alter to or from M2M fields, or add or remove through= on M2M fields)
Run Code Online (Sandbox Code Playgroud)

所以我无法进行迁移.

class InstituteStaff(Person):
    user                 = models.OneToOneField(User, blank=True, null=True)
    investigation_area   = models.ManyToManyField(InvestigationArea, blank=True,)
    investigation_group  = models.ManyToManyField(InvestigationGroup, blank=True)
    council_group        = models.ForeignKey(CouncilGroup, null=True, blank=True)
    #profiles            = models.ManyToManyField(Profiles, null = True, blank = True)
    profiles             = models.ForeignKey(Profiles, null = True, blank = True)
Run Code Online (Sandbox Code Playgroud)

这是我的第一个Django项目,所以欢迎任何建议.

migration django foreign-keys manytomanyfield

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

Sass loader和webpack 4

如何在webpack 4中使用sass loader?我读了很多关于这一点,大多数网站建议使用ExtractTextPlugin,但ExtractTextPlugin不适用于webpack 4.

我写了以下webpack.config.js:

const path = require('path');
const ClosureCompilerPlugin = require('webpack-closure-compiler');


module.exports = {
    module: {
        rules: [
            {
             test: /\.scss$/,
             use: [{
                 loader: "style-loader"
             }, {
                 loader: "css-loader"
             }, {
                 loader: "sass-loader"
             }]
            }
        ]
    },
    plugins: [
        new ClosureCompilerPlugin({
            compiler: {
                language_in: 'ECMASCRIPT6',
                language_out: 'ECMASCRIPT3',
                compilation_level: 'ADVANCED'
            },
            concurrency: 3,
        })
    ]
};
Run Code Online (Sandbox Code Playgroud)

输出.js文件运行良好,但我的.scss没有编译成css.我试图添加入口点:

entry: {
    stylesheet: path.resolve('src', 'scss/styles.scss'),
    main: path.resolve('src', 'index.js')
}
Run Code Online (Sandbox Code Playgroud)

在此之后我的styles.scss编译为stylesheet.js,但我不是.css.

javascript webpack sass-loader

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

django 2.2 中的 UniqueConstraint 不会引发 ValidationError

由于 django 2.2文档建议使用UniqueConstraint而不是unique_together,但是如果提供了属性,则此选项不会在 django admin 中引发 ValidationError 而不覆盖cleanvalidate_unique方法condition

是否可以UniqueConstraint提高ValidationError(在 django admin 中)而不是IntegrityError自己实现验证逻辑?

python django constraints

4
推荐指数
1
解决办法
664
查看次数

将迁移更改写入 django 简单历史记录

django-simple-history书写历史改变instance.save()方法。但是当我写迁移更改实例数据时,更改没有出现。

save()的方法

Model = apps.get_model('myapp', 'MyModel') 
Run Code Online (Sandbox Code Playgroud)

MyModel 
Run Code Online (Sandbox Code Playgroud)

一样吗?有没有办法将这种变化写入历史?

django django-migrations django-simple-history

3
推荐指数
1
解决办法
636
查看次数