简体   繁体   English

Django py manage.py makemigrate

[英]Django py manage.py makemigrate

What can I make with it? 我能用它做什么? I'm beginner in python and django. 我是python和Django的新手。 I download it and I i wrote py manage.py makemigrate and I've get error. 我下载了它,然后写了py manage.py makemigrate,但出现错误。 Can u help me? 你能帮我吗?

You need to supply all environment variables that are listed in your settings file. 您需要提供设置文件中列出的所有环境变量。 Such as DB_NAME that presented in your screenshot. 例如您的屏幕截图中显示的DB_NAME Search for os.environ[<VARIABLE_NAME>] , every VARIABLE_NAME should be defined. 搜索os.environ[<VARIABLE_NAME>] ,应定义每个VARIABLE_NAME

Your issue is with your DB configuration in the setting.py . 您的问题出在setting.py数据库配置。 If you are using the default SQLite then copy/paste this: 如果您使用默认的SQLite,则复制/粘贴以下内容:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

and your project will work just fine. 这样您的项目就可以正常工作。 After this, run 之后,运行

python manage.py makemigrations
python manage.py migrate #copy all migrations to the database
python manage.py createsuperuser #to have a admin user to login to adminpanel
python manage.py runserver #starting the server

Otherwise, take a look at the official documentation how to connect MySQL, PostgreSQL, Oracle databases and required configurations. 否则,请查看官方文档,了解如何连接MySQL,PostgreSQL,Oracle数据库和所需的配置。

Your error is in here : 您的错误在这里

SQLite is not like MySQL or other databases. SQLite与MySQL或其他数据库不同。 Actually, it is not a real database. 实际上,它不是一个真正的数据库。 You are using a port, username, password and etc. These are the cause of the error. 您正在使用端口,用户名,密码等。这些是导致错误的原因。 SQLite is not running in the server or another place. SQLite未在服务器或其他地方运行。 It is just a single file contains data information. 它只是一个包含数据信息的文件。 Update yours to mine above and it should start work again or change your database to MySQL or others. 将您的数据库更新为上面的版本,它将重新开始工作,或者将数据库更改为MySQL或其他数据库。

If you are a beginner it is better to stay with the documentation and do like https://docs.djangoproject.com/en/2.1/intro/tutorial01/ 如果您是初学者,最好继续阅读文档,并像https://docs.djangoproject.com/en/2.1/intro/tutorial01/

If you could share the DB part of the settings.py it would help. 如果您可以共享settings.py的数据库部分,则将有所帮助。

Generally python manage.py startapp appname should create the necessary files for you. 通常, python manage.py startapp appname应为您创建必要的文件。 After which a python manage.py makemigrations and python manage.py migrate should work properly. 在这之后一个python manage.py makemigrationspython manage.py migrate应能正常工作。 And this should not come. 而且这不应该到来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM