小编Mus*_*han的帖子

Django-DB-Migrations:不能ALTER TABLE,因为它有未决的触发事件

我想从TextField中删除null = True:

-    footer=models.TextField(null=True, blank=True)
+    footer=models.TextField(blank=True, default='')
Run Code Online (Sandbox Code Playgroud)

我创建了一个模式迁移:

manage.py schemamigration fooapp --auto
Run Code Online (Sandbox Code Playgroud)

由于一些页脚列包含NULL我得到这个,error如果我运行迁移:

django.db.utils.IntegrityError:列"footer"包含空值

我将此添加到架构迁移中:

    for sender in orm['fooapp.EmailSender'].objects.filter(footer=None):
        sender.footer=''
        sender.save()
Run Code Online (Sandbox Code Playgroud)

现在我得到:

django.db.utils.DatabaseError: cannot ALTER TABLE "fooapp_emailsender" because it has pending trigger events
Run Code Online (Sandbox Code Playgroud)

怎么了?

python django postgresql django-migrations

103
推荐指数
5
解决办法
4万
查看次数

迁移期间的Django NodeNotFoundError

error当我尝试runserver使用我的django应用程序时,我得到如下:

django.db.migrations.graph.NodeNotFoundError:迁移tasks.0001_initial依赖项引用不存在的父节点(u'auth',u'0007_alter_validators_add_error_messages')

这是在我遵循这个heroku教程之后发生的:https://devcenter.heroku.com/articles/getting-started-with-django

我修改了设置文件以包含:

import dj_database_url
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

#DATABASES['default'] =  dj_database_url.config()
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'tasks/static'),
)
Run Code Online (Sandbox Code Playgroud)

我的0001_initial迁移如下:

from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('auth', '0007_alter_validators_add_error_messages'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]
Run Code Online (Sandbox Code Playgroud)

我迷失了我应该尝试下一步来修复此错误.建议赞赏!谢谢!

python sqlite django heroku database-migration

13
推荐指数
1
解决办法
7045
查看次数

无法打开流:HTTP请求失败!HTTP/1.1 400错误请求

我正在访问其他网站的图片.当复制"一些(不是全部)"图像时,我收到"无法打开流:HTTP请求失败!HTTP/1.1 400错误请求"错误.这是我的代码.

$img=$_GET['img']; //another website url
$file=$img;

function getFileextension($file) {
       return end(explode(".", $file));
}
$fileext=getFileextension($file);
if($fileext=='jpg' || $fileext=='gif' || $fileext=='jpeg' || $fileext=='png' || $fileext=='x-png' || $fileext=='pjpeg'){
if($img!=''){
$rand_variable1=rand(10000,100000);
              $node_online_name1=$rand_variable1."image.".$fileext;

                $s=copy($img,"images/".$node_online_name1);
Run Code Online (Sandbox Code Playgroud)

}

http httpwebrequest

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

django select_related用于多个外键

select_related如何使用具有多个外键的模型?它只是选择第一个吗?

class Model:fkey1,fkey2,fkey3 ......

文档没有说明这一点,至少没有说明方法的位置.

django django-select-related

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

用__repr __()理解双引号和单引号之间的区别

是什么区别print,objectrepr()?为什么要以不同的格式打印?

output difference:

>>> x="This is New era"
>>> print x             # print in double quote when with print()
This is New era

>>> x                   #  x display in single quote
'This is New era'

>>> x.__repr__()        # repr() already contain string
"'This is New era'"

>>> x.__str__()         # str() print only in single quote ''
'This is New era'
Run Code Online (Sandbox Code Playgroud)

python repr

5
推荐指数
1
解决办法
705
查看次数

gitlab webhooks:没有数据发布和错误发生

我写了一个asp.net web API来获取gitlab webhooks发布的数据.但是,我无法从gitlab webhooks接收数据.更重要的是,当我点击"Test Hook"按钮时gitlab,出现错误

挂钩执行失败:{"消息"=>"发生错误.在此输入图像描述 "}.我不知道如何解决这个问题!我需要任何帮助!

webhooks gitlab

5
推荐指数
0
解决办法
62
查看次数

如何在React Native中裁剪图像

我正在使用react-native-camera拍照.拍摄的照片是16/9比例,但我需要它们在4/3.

因此我想要的是例如裁剪图像1920*1440.

我使用React Native的ImageEditor.代码ImageEditor可以在这里找到.

我的代码如下:

this.camera.capture(target)
     .then((data) => {
           let cropData = {
               offset:{x:0,y:0},
               size:{width:1920, height:1440}
           };

           ImageEditor.cropImage(
                 data.path,
                 cropData, 
                 (uri) => {
                       this.props.captured(this.props.request, {
                             path: uri,
                             data: data.data,
                             longitude: position.coords.longitude,
                             latitude: position.coords.latitude
                             }
                       );
                       Actions.pop();
                 },
                 (error) => {});
            })
     .catch(err => {
           console.error(err)
     });
Run Code Online (Sandbox Code Playgroud)

但上面的代码不起作用.保存的照片不会被裁剪,它是1440*2560.

有什么建议?

javascript react-native

5
推荐指数
1
解决办法
1338
查看次数

perform lm() inside a piped (%>%) flow: Error of invalid term in model formula

I intend to perform separate regression by each level of a factor in a data.frame. I used to be able to do it by using plyr::ddply . However, when I tried to use the pipe flow of analysis, I encountered the following errors. Please advise how to overcome it, or I will have to revert to plyr::ddply , etc. Thanks.

d = data.frame(
Gender = c("M","F"),
Age = rnorm(20, mean = 40, sd = 3),
Weight = rnorm(20, mean=70, sd=5) …
Run Code Online (Sandbox Code Playgroud)

group-by r lm dplyr

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

如何在OSX应用程序中运行嵌入式二进制文件?

我有一个需要运行外部程序的应用程序.

我把这个程序作为一个Embedded Framework.存档时,它会显示在该位置%AppRoot%/Contents/Frameworks/MyExternalApplication.

如何在不使用绝对路径的情况下从应用程序代码运行此程序?我想在发布和调试中运行.

谢谢!

macos xcode objective-c

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

在using语句中通过工厂创建一次性对象

假定基类Foo实现IDisposable。类FooAFooB继承Foo类。一个简单的工厂方法,FooFactory.Create()根据客户端的需要返回FooA或FooB对象。

在下面的客户端代码(FooTest模块)中,尝试在“使用”语句中使用工厂方法会导致以下编译错误:

“使用”资源变量必须具有显式初始化。

我非常感谢有关通过Using语句支持实例化FooA或FooB(由客户端指定)的实现的任何建议(最佳实践)。不需要工厂-这只是我尝试的方法。理想情况下,我希望FooA和FooB是具有公共基类或接口的独立类。

在此先感谢您提供的任何帮助。

Public Module FooTest

    Public Sub Test()
        'the following compiles:
        Dim f As Foo = FooFactory.Create("A")
        f.DoWork()
        f.Dispose()
        'the following causes a compile error:
        ''Using' resource variable must have an explicit initialization.
        Using f As FooFactory.Create("A")
            f.DoWork()
        End Using
    End Sub

End Module

Public Module FooFactory

    Public Function Create(ByVal AorB As String) As Foo
        If AorB = "A" Then
            Return New FooA
        Else
            Return New FooB
        End If
    End Function …
Run Code Online (Sandbox Code Playgroud)

vb.net factory using-statement

2
推荐指数
1
解决办法
216
查看次数