会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132843个问题
Python 全系列/第一阶段:Python入门/编程基本概念 35581楼
JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 35584楼

from django.db import models

# Create your models here.
class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField()

上面是orm类

下面是python manage.py makemigrations mosel_app创建得0001

# Generated by Django 2.2.6 on 2019-10-25 02:46

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Question',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('question_text', models.CharField(max_length=200)),
                ('pub_date', models.DateTimeField()),
            ],
        ),
    ]

但是在cmd运行python manage.py migrate  出现下面错误

Operations to perform:

  Apply all migrations: admin, auth, contenttypes, model_app, sessions

Running migrations:

Traceback (most recent call last):

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\backends\utils.py", line 82, in _execute

    return self.cursor.execute(sql)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute

    return self.cursor.execute(query, args)

  File "D:\python_virtualEnv\django_env\lib\site-packages\MySQLdb\cursors.py", line 209, in execute

    res = self._query(query)

  File "D:\python_virtualEnv\django_env\lib\site-packages\MySQLdb\cursors.py", line 315, in _query

    db.query(q)

  File "D:\python_virtualEnv\django_env\lib\site-packages\MySQLdb\connections.py", line 226, in query

    _mysql.connection.query(self, query)

MySQLdb._exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL)' at line 1")


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\migrations\recorder.py", line 67, in ensure_schema

    editor.create_model(self.Migration)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\backends\base\schema.py", line 307, in create_model

    self.execute(sql, params or None)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\backends\base\schema.py", line 137, in execute

    cursor.execute(sql, params)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\backends\utils.py", line 99, in execute

    return super().execute(sql, params)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\backends\utils.py", line 67, in execute

    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers

    return executor(sql, params, many, context)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\backends\utils.py", line 84, in _execute

    return self.cursor.execute(sql, params)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\utils.py", line 89, in __exit__

    raise dj_exc_value.with_traceback(traceback) from exc_value

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\backends\utils.py", line 82, in _execute

    return self.cursor.execute(sql)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute

    return self.cursor.execute(query, args)

  File "D:\python_virtualEnv\django_env\lib\site-packages\MySQLdb\cursors.py", line 209, in execute

    res = self._query(query)

  File "D:\python_virtualEnv\django_env\lib\site-packages\MySQLdb\cursors.py", line 315, in _query

    db.query(q)

  File "D:\python_virtualEnv\django_env\lib\site-packages\MySQLdb\connections.py", line 226, in query

    _mysql.connection.query(self, query)

django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL)' at line 1")


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "manage.py", line 21, in <module>

    main()

  File "manage.py", line 17, in main

    execute_from_command_line(sys.argv)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line

    utility.execute()

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\core\management\__init__.py", line 375, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv

    self.execute(*args, **cmd_options)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\core\management\base.py", line 364, in execute

    output = self.handle(*args, **options)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\core\management\base.py", line 83, in wrapped

    res = handle_func(*args, **kwargs)

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\core\management\commands\migrate.py", line 234, in handle

    fake_initial=fake_initial,

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\migrations\executor.py", line 91, in migrate

    self.recorder.ensure_schema()

  File "D:\python_virtualEnv\django_env\lib\site-packages\django\db\migrations\recorder.py", line 69, in ensure_schema

    raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)

django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ((1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL)' at line 1"))

提示我一个语法错误,什么NOT NULL,这是什么意思???

Python 全系列/第十二阶段:Python_Django3框架/Django初级 35586楼
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 35587楼
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 35588楼
JAVA 全系列/(旧的隐藏)第十一阶段:spring全家桶(Spring Boot)/Spring Boot 35591楼
Python 全系列/第一阶段:Python入门/序列 35593楼
Python 全系列/第五阶段:数据库编程/mysql的使用 35595楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637