Nico
Nico

Reputation: 3

Django mange.py migrate --> No Migration folder and no tables created

I recently started to experiment with python and Django at the same time. After playing with several little projects from GitHub and or youtube and tried do it from scratch now on my own.

My problem is, the command

python manage.py migrate

Only creates those 10 "standard" Django and "auth" tables in my local mysql db.

Attached you can find my project structure. The way I started was with " django-admin startproject Nico".

enter image description here

Then step after step've created models, views, forms and templates.

My best guess is, the migrate command does not find the models file. But I don't know where to specify that. At least that is a missing link. In my previous examples which were complete, I never had to declare that. Would that go in the right direction?

views.py

from django.views.generic.base import TemplateView

from ReProg.ReProg.models import Kunde
from ReProg.ReProg.forms import KundeForm

class HP(TemplateView):
    Model = Kunde
    Form = KundeForm
    #template_name = "TestViewHello.html"
    #template_name = "KundenAufnahme.html"
    template_name = "KundenAufnahme2.html"

forms.py

from django import forms
from django.http import HttpResponse, HttpResponseNotFound
from django.shortcuts import render
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit


class KundeForm(forms.Form):
    #KID = forms.CharField(attrs={'disabled': True})
    KID = forms.CharField()
    first_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'ReProg'}))
    last_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Wilhelm'}))
    email = forms.CharField(widget=forms.TextInput(attrs={'placeholder': '[email protected]'}))
    def __init__(self, *args, **kwargs):
        super(KundeForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_method = 'post'
        self.helper.add_input(Submit('submit', 'Submit'))

Models.py

from django.db import models
from django.forms import ModelForm
from datetime import date


###########Kunde
class Kunde(models.Model):
    KID = models.CharField(primary_key=True, max_length=20)
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    email = models.EmailField(max_length=100, blank=True)
def KID(key):
    num = Request.objects.all().count()
    return K + str(num)

class KundeMF(ModelForm):
    class Meta:
        model = Kunde
        fields = ['first_name', 'last_name', 'KID']

settings.py

Django settings for ReProg project.

Generated by 'django-admin startproject' using Django 3.1.5.

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

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

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '+e69jgm56u85imt)(=6@82@c60222e9-z0+h8b+kxwhe(kc*z4'

# SECURITY WARNING: don't run with debug turned on in production!
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',
    'ReProg',
    'crispy_forms',
]
CRISPY_TEMPLATE_PACK = 'bootstrap4'


MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '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 = 'ReProg.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "templates")],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'ReProg.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'ReProg',
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.1/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/3.1/howto/static-files/

STATIC_URL = '/static/'

Upvotes: 0

Views: 1547

Answers (3)

Nico
Nico

Reputation: 3

it worked with adding the

i forgot to mention that before migrating I executed "makemigrations". However it said "no changes detected" or something similar.

Now with the it works. I can see the table now in mysql. [enter image description here][1]

thx all [1]: https://i.sstatic.net/HaKFg.png

Upvotes: 0

AlASAD WAIL
AlASAD WAIL

Reputation: 825

first make the following

python manage.py makemigrations
python manage.py migrate

if the problem did not solved make the following:

1- If the folder migrations did not found in the app directory create it.

2- If the folder found check the __init__.py file inside the folder. if this file did not found create new file with name __init__.py.

Upvotes: 1

04k
04k

Reputation: 175

  1. python manage.py makemigrations <app name>
  2. python manage.py migrate <app name>

Upvotes: 2

Related Questions