Santiago Buchini
Santiago Buchini

Reputation: 13

Import "django.db.models" could not be resolved from source / py manage.py makemigrations No changes detected

I am working on a project using django and I am using Visual Studio Code software.

In my 'store' directory i have a python package called 'tiendaonline' and the app called "gestionpedidos" where I am trying to create a a Table (DDBB)

The problem i am getting is that I cannot create table because when I try to run "py manage.py makemigrations" I can see the msg "No changes detected". Also I can see in the window called problems this msg: " Import "django.db.models" could not be resolved from source "

My setting.py is like this:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'gestionpedidos',
]

and my model is this:

from django.db import models

# Create your models here.
class Pedidos(models.Model):
    numero = models.IntegerField(max_length=100 )
    fecha = models.DateField(max_length=300 )
    entregado = models.BooleanField() 

class Clientes(models.Model):
    name = models.CharField(max_length=30 )
    direc = models.CharField(max_length=50 )
    Email = models.EmailField() 
    Tel = models.EmailField() 

class Articulos(models.Model):
    name = models.CharField(max_length=100 )
    seccion = models.CharField(max_length=300 )
    price = models.IntegerField() 

I don't know what is happening. It could give me an adress of migration like "0001_init" but is not running.

Upvotes: 1

Views: 11640

Answers (4)

Aprendiz
Aprendiz

Reputation: 33

If you are using VSCode, you can also select the Python Interpreter by clicking on the bottom right corner of the screen. Your project and your interpreter must be in the same environment. See how to select it in the image. Select Enviroment

Upvotes: 1

Dx bros
Dx bros

Reputation: 31

Go to view > command Palette > Python: select interpreter > { select the one where Django is installed }. This worked for me .

Upvotes: 3

Elias Amha
Elias Amha

Reputation: 349

If django is not detecting the changes do this py manage.py makemigrations gestionpedidos to look for changes in that app only. I'm not sure why but this has worked for me countless times in the past.

Upvotes: 1

I'mSRJ
I'mSRJ

Reputation: 315

restart your vs code first and then activate your virtual environment if you are using. do again makemigrations and migrate if still no changes detected then delete recent migration and do it again

Upvotes: 4

Related Questions