Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法迁移以及如何使用Django python设置mysql数据库_Python_Mysql_Django - Fatal编程技术网

无法迁移以及如何使用Django python设置mysql数据库

无法迁移以及如何使用Django python设置mysql数据库,python,mysql,django,Python,Mysql,Django,我是Django python的初学者。当我遇到这个python manage.py migrate时,我得到了以下错误 Unknown command: 'migrate' Type 'manage.py help' for usage. 这里我还尝试创建一个crud应用程序,其中包含MYSQL数据库,该数据库位于localhost中,这意味着我需要连接到我的localhost数据库。我还需要知道如何在settings.py文件中使用所有凭据连接它。下面给出了我的settings.py文件

我是Django python的初学者。当我遇到这个
python manage.py migrate
时,我得到了以下错误

Unknown command: 'migrate'
Type 'manage.py help' for usage.
这里我还尝试创建一个crud应用程序,其中包含
MYSQL
数据库,该数据库位于localhost中,这意味着我需要连接到我的localhost数据库。我还需要知道如何在
settings.py
文件中使用所有凭据连接它。下面给出了我的
settings.py
文件

设置.py

"""
Django settings for mysite project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '#=0(1b4%2y!3(hs%_4v&_*(-j#c#8__s6^=1+b0eqrar7810h+'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

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

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'
请帮助我解决上述问题并连接到DB。

命令可在Django 1.7及更高版本中找到。您应该使用
syncdb
它所能做的就是根据您的模型为您创建一个数据库表和行


如果您想在Django 1.6上进行最新Django的迁移,请考虑使用

默认数据库:SqLITE3

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

'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'django',
        'USER' : 'username',
        'PASSWORD' : 'password',
        'HOST' : 'your ip',
        'PORT' : 'port',
    }
在django新版本中。我必须执行3个步骤才能迁移

python manage.py makemigrations <app_name>
python manage.py sqlmigrate svace <version of data>
python manage.py migrate
python manage.py makemigrations
python manage.py sqlmigrate svace
python manage.py迁移

答案结束首先,如果您有要迁移的数据,请执行以下命令:

python manage.py dumpdata > datadump.json
下一步:将数据库配置更改为MySql:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'your-db-name',
        'USER': 'your-username',
        'PASSWORD': 'your-password',
        'HOST': 'localhost',
        'PORT': '',
    },
}
然后执行:

python manage.py makemigrations
python manage.py migrate
要还原数据类型,请执行以下操作:

python manage.py loaddata datadump.json

根据your settings.py中的注释,您已经下载了django 1.6,而该功能从django 1.7开始就可以使用。也许
syncdb
会有所帮助……此外,settings.py与未知命令无关:请参阅管理。py@RajaSimon:你能发布你的解决方案吗?抛开这个古老的版本,绝对没有理由用它开始一个新项目。我理解,但如何使用代码文件中的那些内容,因为我是全新的,正在尝试学习这些语言。你不必做主要的代码代码库中的更改。安装指令将在这里找到,这是重要的,然后在这里,为什么不考虑切换到最新Django?