Compiler gives an import mistake in python3-django model after few mistakes with migrationsdjango - inlineformset_factory with more than one ForeignKeyShow information of subclass in list_display djangoDjango - queries across relationshipsDjango south migration error with unique field in postgresql databaseProducts catalogue: filter by parametersRadio buttons in django adminHow to expose some specific fields of model_b based on a field of model_a?How to set dynamic initial values to django modelform fieldHow to define Mode with generic ForeignKey in DjangoHow to check if Django Signal works?

How to say in German "enjoying home comforts"

I'm flying to France today and my passport expires in less than 2 months

Today is the Center

How could indestructible materials be used in power generation?

Is there a hemisphere-neutral way of specifying a season?

How can I make my BBEG immortal short of making them a Lich or Vampire?

Is it legal for company to use my work email to pretend I still work there?

1960's book about a plague that kills all white people

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

How is it possible to have an ability score that is less than 3?

How to prevent "they're falling in love" trope

Why does Kotter return in Welcome Back Kotter

How to take photos in burst mode, without vibration?

Twin primes whose sum is a cube

AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?

Why are electrically insulating heatsinks so rare? Is it just cost?

Would Slavery Reparations be considered Bills of Attainder and hence Illegal?

How can I tell someone that I want to be his or her friend?

Why do I get two different answers for this counting problem?

How much of data wrangling is a data scientist's job?

Arrow those variables!

Memorizing the Keyboard

Can a virus destroy the BIOS of a modern computer?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?



Compiler gives an import mistake in python3-django model after few mistakes with migrations


django - inlineformset_factory with more than one ForeignKeyShow information of subclass in list_display djangoDjango - queries across relationshipsDjango south migration error with unique field in postgresql databaseProducts catalogue: filter by parametersRadio buttons in django adminHow to expose some specific fields of model_b based on a field of model_a?How to set dynamic initial values to django modelform fieldHow to define Mode with generic ForeignKey in DjangoHow to check if Django Signal works?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















I have a basic django practice assignment for my Python courses. It is to write a model for the hypothetical Internet shop application. I have written a model but cannot submit it until it is checked properly by a compiler in the virtual environment. I am aware that as it is the code itself is imperfect from the point of view of business logic. But the compiler's mistake is the main thing now because I cannot move forward with it.
I have followed the django official tutorial to create a project. I have started the project and ran a server.
I wrote not so good code for the model and made migrations. Then I almost completely rewrote it and tried to use manage.py shell. But now the compiler gave a mistake. It was the django.core raising one of its errors concerning the settings file. It didn't work out and thought I have to make migrations again. Now it gave the db API mistake saying the path to the file is too long (I am using postgressql). Important detail - I have moved the files one level and renamed the folder containing them. From that point I have tried everything. I have edited settings file few times and made different imports in the file of the model itself. The result is the same compilers mistake:



ImportError: cannot import name 'DEFAULT_SETTINGS_MODULE' from 'manage' (/home/bodhi/PycharmProjects/Internet_shop/manage.py)


I have found similar problems with the models migrations for django here, at stackoverflow but no advice from them worked for me.
The code for my model:



import sys, os
sys.path.insert(0, "/home/bodhi/PycharmProjects/Internet_shop/manage.py")

from manage import DEFAULT_SETTINGS_MODULE
os.environ.setdefault(DJANGO_SETTINGS_MODULE="/home/bodhi/PycharmProjects/Internet_shop/internet/settings.py")

import django
django.setup()

from django.db import models


class Categories (models.Model):
name = models.CharField(max_length=200, unique=True)
add_category = models.CharField(max_length=200, unique=True)
remove_category = models.CharField(max_length=200, unique=True)


class Item (models.Model):
name = models.CharField(max_length=200, unique=True)
price = models.DecimalField(max_length=9, max_decimal_places=2)
quantity = models.DecimalField(max_length=9, max_decimal_places=2)
category_name = models.ForeignKey(Categories, on_delete=models.CASCADE)
add_item = models.CharField(max_length=200, unique=True)
remove_item = models.CharField(max_length=200, unique=True)


class OrderBasket (models.Model):
add_item = models.ForeignKey(Item, on_delete=models.CASCADE)
remove_item = models.ForeignKey(Item, on_delete=models.CASCADE)
delete_all = models.CharField(on_delete=models.CASCADE)
count_order = models.ForeignKey(Item.price, on_delete=models.CASCADE)


class User (models.Model):
user_login = models.EmailField(max_length=200, unique=True)
money = models.DecimalField(max_length=9)
order_history = models.ForeignKey(OrderBasket, on_delete=models.CASCADE)









share|improve this question






















  • This isn't how you write a models file. You don't need to import that setting at all, nor mess with the environment or the path, or call setup. Why are you doing those things?

    – Daniel Roseman
    Mar 21 at 22:30











  • Well, I am inexperienced, as was said in the initial post. I have commited mistakes but I don't know how to fix them so I am asking for help.

    – bodhi
    Mar 22 at 16:29











  • But being inexperienced doesn't lead you to writing random lines. They are not mentioned in the Django tutorial, so you got them from somewhere - where? Anyway, remove those initial 9 lines and just have models code in your models files.

    – Daniel Roseman
    Mar 22 at 16:43

















-1















I have a basic django practice assignment for my Python courses. It is to write a model for the hypothetical Internet shop application. I have written a model but cannot submit it until it is checked properly by a compiler in the virtual environment. I am aware that as it is the code itself is imperfect from the point of view of business logic. But the compiler's mistake is the main thing now because I cannot move forward with it.
I have followed the django official tutorial to create a project. I have started the project and ran a server.
I wrote not so good code for the model and made migrations. Then I almost completely rewrote it and tried to use manage.py shell. But now the compiler gave a mistake. It was the django.core raising one of its errors concerning the settings file. It didn't work out and thought I have to make migrations again. Now it gave the db API mistake saying the path to the file is too long (I am using postgressql). Important detail - I have moved the files one level and renamed the folder containing them. From that point I have tried everything. I have edited settings file few times and made different imports in the file of the model itself. The result is the same compilers mistake:



ImportError: cannot import name 'DEFAULT_SETTINGS_MODULE' from 'manage' (/home/bodhi/PycharmProjects/Internet_shop/manage.py)


I have found similar problems with the models migrations for django here, at stackoverflow but no advice from them worked for me.
The code for my model:



import sys, os
sys.path.insert(0, "/home/bodhi/PycharmProjects/Internet_shop/manage.py")

from manage import DEFAULT_SETTINGS_MODULE
os.environ.setdefault(DJANGO_SETTINGS_MODULE="/home/bodhi/PycharmProjects/Internet_shop/internet/settings.py")

import django
django.setup()

from django.db import models


class Categories (models.Model):
name = models.CharField(max_length=200, unique=True)
add_category = models.CharField(max_length=200, unique=True)
remove_category = models.CharField(max_length=200, unique=True)


class Item (models.Model):
name = models.CharField(max_length=200, unique=True)
price = models.DecimalField(max_length=9, max_decimal_places=2)
quantity = models.DecimalField(max_length=9, max_decimal_places=2)
category_name = models.ForeignKey(Categories, on_delete=models.CASCADE)
add_item = models.CharField(max_length=200, unique=True)
remove_item = models.CharField(max_length=200, unique=True)


class OrderBasket (models.Model):
add_item = models.ForeignKey(Item, on_delete=models.CASCADE)
remove_item = models.ForeignKey(Item, on_delete=models.CASCADE)
delete_all = models.CharField(on_delete=models.CASCADE)
count_order = models.ForeignKey(Item.price, on_delete=models.CASCADE)


class User (models.Model):
user_login = models.EmailField(max_length=200, unique=True)
money = models.DecimalField(max_length=9)
order_history = models.ForeignKey(OrderBasket, on_delete=models.CASCADE)









share|improve this question






















  • This isn't how you write a models file. You don't need to import that setting at all, nor mess with the environment or the path, or call setup. Why are you doing those things?

    – Daniel Roseman
    Mar 21 at 22:30











  • Well, I am inexperienced, as was said in the initial post. I have commited mistakes but I don't know how to fix them so I am asking for help.

    – bodhi
    Mar 22 at 16:29











  • But being inexperienced doesn't lead you to writing random lines. They are not mentioned in the Django tutorial, so you got them from somewhere - where? Anyway, remove those initial 9 lines and just have models code in your models files.

    – Daniel Roseman
    Mar 22 at 16:43













-1












-1








-1








I have a basic django practice assignment for my Python courses. It is to write a model for the hypothetical Internet shop application. I have written a model but cannot submit it until it is checked properly by a compiler in the virtual environment. I am aware that as it is the code itself is imperfect from the point of view of business logic. But the compiler's mistake is the main thing now because I cannot move forward with it.
I have followed the django official tutorial to create a project. I have started the project and ran a server.
I wrote not so good code for the model and made migrations. Then I almost completely rewrote it and tried to use manage.py shell. But now the compiler gave a mistake. It was the django.core raising one of its errors concerning the settings file. It didn't work out and thought I have to make migrations again. Now it gave the db API mistake saying the path to the file is too long (I am using postgressql). Important detail - I have moved the files one level and renamed the folder containing them. From that point I have tried everything. I have edited settings file few times and made different imports in the file of the model itself. The result is the same compilers mistake:



ImportError: cannot import name 'DEFAULT_SETTINGS_MODULE' from 'manage' (/home/bodhi/PycharmProjects/Internet_shop/manage.py)


I have found similar problems with the models migrations for django here, at stackoverflow but no advice from them worked for me.
The code for my model:



import sys, os
sys.path.insert(0, "/home/bodhi/PycharmProjects/Internet_shop/manage.py")

from manage import DEFAULT_SETTINGS_MODULE
os.environ.setdefault(DJANGO_SETTINGS_MODULE="/home/bodhi/PycharmProjects/Internet_shop/internet/settings.py")

import django
django.setup()

from django.db import models


class Categories (models.Model):
name = models.CharField(max_length=200, unique=True)
add_category = models.CharField(max_length=200, unique=True)
remove_category = models.CharField(max_length=200, unique=True)


class Item (models.Model):
name = models.CharField(max_length=200, unique=True)
price = models.DecimalField(max_length=9, max_decimal_places=2)
quantity = models.DecimalField(max_length=9, max_decimal_places=2)
category_name = models.ForeignKey(Categories, on_delete=models.CASCADE)
add_item = models.CharField(max_length=200, unique=True)
remove_item = models.CharField(max_length=200, unique=True)


class OrderBasket (models.Model):
add_item = models.ForeignKey(Item, on_delete=models.CASCADE)
remove_item = models.ForeignKey(Item, on_delete=models.CASCADE)
delete_all = models.CharField(on_delete=models.CASCADE)
count_order = models.ForeignKey(Item.price, on_delete=models.CASCADE)


class User (models.Model):
user_login = models.EmailField(max_length=200, unique=True)
money = models.DecimalField(max_length=9)
order_history = models.ForeignKey(OrderBasket, on_delete=models.CASCADE)









share|improve this question














I have a basic django practice assignment for my Python courses. It is to write a model for the hypothetical Internet shop application. I have written a model but cannot submit it until it is checked properly by a compiler in the virtual environment. I am aware that as it is the code itself is imperfect from the point of view of business logic. But the compiler's mistake is the main thing now because I cannot move forward with it.
I have followed the django official tutorial to create a project. I have started the project and ran a server.
I wrote not so good code for the model and made migrations. Then I almost completely rewrote it and tried to use manage.py shell. But now the compiler gave a mistake. It was the django.core raising one of its errors concerning the settings file. It didn't work out and thought I have to make migrations again. Now it gave the db API mistake saying the path to the file is too long (I am using postgressql). Important detail - I have moved the files one level and renamed the folder containing them. From that point I have tried everything. I have edited settings file few times and made different imports in the file of the model itself. The result is the same compilers mistake:



ImportError: cannot import name 'DEFAULT_SETTINGS_MODULE' from 'manage' (/home/bodhi/PycharmProjects/Internet_shop/manage.py)


I have found similar problems with the models migrations for django here, at stackoverflow but no advice from them worked for me.
The code for my model:



import sys, os
sys.path.insert(0, "/home/bodhi/PycharmProjects/Internet_shop/manage.py")

from manage import DEFAULT_SETTINGS_MODULE
os.environ.setdefault(DJANGO_SETTINGS_MODULE="/home/bodhi/PycharmProjects/Internet_shop/internet/settings.py")

import django
django.setup()

from django.db import models


class Categories (models.Model):
name = models.CharField(max_length=200, unique=True)
add_category = models.CharField(max_length=200, unique=True)
remove_category = models.CharField(max_length=200, unique=True)


class Item (models.Model):
name = models.CharField(max_length=200, unique=True)
price = models.DecimalField(max_length=9, max_decimal_places=2)
quantity = models.DecimalField(max_length=9, max_decimal_places=2)
category_name = models.ForeignKey(Categories, on_delete=models.CASCADE)
add_item = models.CharField(max_length=200, unique=True)
remove_item = models.CharField(max_length=200, unique=True)


class OrderBasket (models.Model):
add_item = models.ForeignKey(Item, on_delete=models.CASCADE)
remove_item = models.ForeignKey(Item, on_delete=models.CASCADE)
delete_all = models.CharField(on_delete=models.CASCADE)
count_order = models.ForeignKey(Item.price, on_delete=models.CASCADE)


class User (models.Model):
user_login = models.EmailField(max_length=200, unique=True)
money = models.DecimalField(max_length=9)
order_history = models.ForeignKey(OrderBasket, on_delete=models.CASCADE)






python django postgresql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 21 at 21:50









bodhibodhi

11




11












  • This isn't how you write a models file. You don't need to import that setting at all, nor mess with the environment or the path, or call setup. Why are you doing those things?

    – Daniel Roseman
    Mar 21 at 22:30











  • Well, I am inexperienced, as was said in the initial post. I have commited mistakes but I don't know how to fix them so I am asking for help.

    – bodhi
    Mar 22 at 16:29











  • But being inexperienced doesn't lead you to writing random lines. They are not mentioned in the Django tutorial, so you got them from somewhere - where? Anyway, remove those initial 9 lines and just have models code in your models files.

    – Daniel Roseman
    Mar 22 at 16:43

















  • This isn't how you write a models file. You don't need to import that setting at all, nor mess with the environment or the path, or call setup. Why are you doing those things?

    – Daniel Roseman
    Mar 21 at 22:30











  • Well, I am inexperienced, as was said in the initial post. I have commited mistakes but I don't know how to fix them so I am asking for help.

    – bodhi
    Mar 22 at 16:29











  • But being inexperienced doesn't lead you to writing random lines. They are not mentioned in the Django tutorial, so you got them from somewhere - where? Anyway, remove those initial 9 lines and just have models code in your models files.

    – Daniel Roseman
    Mar 22 at 16:43
















This isn't how you write a models file. You don't need to import that setting at all, nor mess with the environment or the path, or call setup. Why are you doing those things?

– Daniel Roseman
Mar 21 at 22:30





This isn't how you write a models file. You don't need to import that setting at all, nor mess with the environment or the path, or call setup. Why are you doing those things?

– Daniel Roseman
Mar 21 at 22:30













Well, I am inexperienced, as was said in the initial post. I have commited mistakes but I don't know how to fix them so I am asking for help.

– bodhi
Mar 22 at 16:29





Well, I am inexperienced, as was said in the initial post. I have commited mistakes but I don't know how to fix them so I am asking for help.

– bodhi
Mar 22 at 16:29













But being inexperienced doesn't lead you to writing random lines. They are not mentioned in the Django tutorial, so you got them from somewhere - where? Anyway, remove those initial 9 lines and just have models code in your models files.

– Daniel Roseman
Mar 22 at 16:43





But being inexperienced doesn't lead you to writing random lines. They are not mentioned in the Django tutorial, so you got them from somewhere - where? Anyway, remove those initial 9 lines and just have models code in your models files.

– Daniel Roseman
Mar 22 at 16:43












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55289789%2fcompiler-gives-an-import-mistake-in-python3-django-model-after-few-mistakes-with%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55289789%2fcompiler-gives-an-import-mistake-in-python3-django-model-after-few-mistakes-with%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현