我正在尝试将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项目,所以欢迎任何建议.
如何在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.
由于 django 2.2文档建议使用UniqueConstraint
而不是unique_together
,但是如果提供了属性,则此选项不会在 django admin 中引发 ValidationError 而不覆盖clean
或validate_unique
方法condition
。
是否可以UniqueConstraint
提高ValidationError
(在 django admin 中)而不是IntegrityError
自己实现验证逻辑?
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 ×3
constraints ×1
foreign-keys ×1
javascript ×1
migration ×1
python ×1
sass-loader ×1
webpack ×1