“无”附近:运行python程序时出现语法错误

时间:2018-06-13 14:45:27

标签: python django visual-studio

我基于excel数据在sqlite3数据库中动态创建模型。我正在使用pandas readexcel()方法读取excel数据。当我运行程序系统时显示错误'near“无”:语法错误'。

错误消息 / home /的OperationalError “无”附近:语法错误 请求方法:GET 请求网址:http://localhost:61157/home/ Django版本:1.11.13 异常类型:OperationalError 例外价值:
“无”附近:语法错误 异常位置:执行中的C:\ Users \ 1297805 \ Documents \ Visual Studio 2013 \ Projects \ DashBoardApplication \ DashBoardApplication \ DashBoardEnv \ lib \ site-packages \ django \ db \ backends \ sqlite3 \ base.py,第326行 Python可执行文件:C:\ Users \ 1297805 \ Documents \ Visual Studio 2013 \ Projects \ DashBoardApplication \ DashBoardApplication \ DashBoardEnv \ Scripts \ python.exe Python版本:3.6.5 Python路径:
['C:\ Users \ 1297805 \ Documents \ Visual Studio'  '2013 \项目\ DashBoardApplication \ DashBoardApplication',  'C:\ Users \ 1297805 \ Documents \ Visual Studio'  '2013 \项目\ DashBoardApplication \ DashBoardApplication \ DashBoardEnv \脚本\ python36.zip',  'C:\用户\ ADMIN \应用程序数据\本地\程序\ Python的\ Python36 \ DLL文件',  'C:\用户\ ADMIN \应用程序数据\本地\程序\ Python的\ Python36 \ lib中',  'C:\用户\ ADMIN \应用程序数据\本地\程序\ Python的\ Python36',  'C:\ Users \ 1297805 \ Documents \ Visual Studio'  '2013 \项目\ DashBoardApplication \ DashBoardApplication \ DashBoardEnv',  'C:\ Users \ 1297805 \ Documents \ Visual Studio'  '2013 \项目\ DashBoardApplication \ DashBoardApplication \ DashBoardEnv \ lib中\站点包']

服务器时间:2018年6月13日星期三09:08:35 -0500

**阅读Excel数据**

df = pd.read_excel(path_to_csv, encoding='utf-8')
    col_names = df.columns
fields = {}
for name in col_names:
    fields[name] =  models.CharField()
return create_model('userdata',fields,'startapp')

创建模型

    def create_model(name, fields=None, app_label='', module='', 
          options=None,admin_opts=None):
    class Meta:
        # Using type('Meta', ...) gives a dictproxy error during model 
        creation
           pass

    if app_label:
        # app_label must be set using the Meta inner class
        setattr(Meta, 'app_label', app_label)

    # Update Meta with any options that were provided
    if options is not None:
        for key, value in options.iteritems():
            setattr(Meta, key, value)

    # Set up a dictionary to simulate declarations within a class
    attrs = {'__module__': module, 'Meta': Meta}

    # Add in any fields that were provided
    if fields:
        attrs.update(fields)

    # Create the class, which automatically triggers ModelBase processing
    model = type(name, (models.Model,), attrs)

    # Create an Admin class if admin options were provided
    if admin_opts is not None:
         class Admin(admin.ModelAdmin):
            pass
        for key, value in admin_opts:
            setattr(Admin, key, value)
        admin.site.register(model, Admin)

 return model
def install(model):
    from django.db import connection

    with connection.schema_editor() as editor:
                return editor.create_model(model)

为什么我收到错误?

1 个答案:

答案 0 :(得分:0)

Django自1.11以来发生了很大的变化我会建议你将Django升级到至少2.0,因为他们已经做了很多事情并且修复了很多错误。