adilmohak / django-lms

A learning management system using django web framework. Course add and drop, grade and assessment result management, online quiz, report generator, student and lecturers management, dashboard, and so much more...
MIT License
474 stars 197 forks source link

I can't run "python manage.py migrate", please give solution #29

Open sahal-git opened 4 months ago

sahal-git commented 4 months ago

PS C:\Users\ARSHAD\Documents\GitHub\django-lms> python manage.py migrate
Traceback (most recent call last): File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\backends\base\base.py", line 244, in ensure_connection self.connect() File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\backends\base\base.py", line 225, in connect self.connection = self.get_new_connection(conn_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\backends\postgresql\base.py", line 203, in get_new_connection connection = Database.connect(conn_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\psycopg2__init__.py", line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ psycopg2.OperationalError: connection to server at "localhost" (::1), port 5432 failed: FATAL: role "[DB_ADMIN_NAME]" does not exist

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\ARSHAD\Documents\GitHub\django-lms\manage.py", line 21, in main() File "C:\Users\ARSHAD\Documents\GitHub\django-lms\manage.py", line 17, in main execute_from_command_line(sys.argv) File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\core\management__init.py", line 446, in execute_from_command_line utility.execute() File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\core\management__init.py", line 440, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\core\management\base.py", line 414, in run_from_argv self.execute(*args, cmd_options) File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\core\management\base.py", line 460, in execute output = self.handle(*args, *options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\core\management\base.py", line 98, in wrapped res = handle_func(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\core\management\commands\migrate.py", line 91, in handle self.check(databases=[database]) File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\core\management\base.py", line 487, in check
all_issues = checks.run_checks( ^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\core\checks\registry.py", line 88, in run_checks new_errors = check(app_configs=app_configs, databases=databases) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\core\checks\model_checks.py", line 36, in check_all_models errors.extend(model.check(*kwargs)) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\models\base.py", line 1461, in check
cls._check_indexes(databases), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\models\base.py", line 1864, in _check_indexes connection.features.supports_covering_indexes File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\utils\functional.py", line 49, in
get
res = instance.
dict__[self.name] = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\backends\postgresql\features.py", line 84, in is_postgresql_11 return self.connection.pg_version >= 110000 ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\utils\functional.py", line 49, in
get
res = instance.
dict[self.name] = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\backends\postgresql\base.py", line 354, in pg_version with self.temporary_connection(): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64qbz5n2kfra8p0\Lib\contextlib.py", line 137, in enter return next(self.gen) ^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\backends\base\base.py", line 639, in temporary_connection with self.cursor() as cursor: ^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\backends\base\base.py", line 284, in cursor return self._cursor() ^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\backends\base\base.py", line 260, in _cursor self.ensure_connection() File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\backends\base\base.py", line 243, in ensure_connection with self.wrap_database_errors: File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\utils.py", line 91, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\backends\base\base.py", line 244, in ensure_connection self.connect() File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\backends\base\base.py", line 225, in connect self.connection = self.get_new_connection(conn_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\django\db\backends\postgresql\base.py", line 203, in get_new_connection connection = Database.connect(conn_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ARSHAD\Documents\GitHub\django-lms\venv\Lib\site-packages\psycopg2__init__.py", line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, kwasync) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ django.db.utils.OperationalError: connection to server at "localhost" (::1), port 5432 failed: FATAL: role "[DB_ADMIN_NAME]**" does not exist

### Source code:

CODE_OF_CONDUCT.md CONTRIBUTING.md README.md requirements.txt TODO.md

jrubialesv commented 4 months ago

Seems to be a problem with the setup of the Postgres DDBB. Could you explain further? Did you create an .env and change the values?

adilmohak commented 2 months ago

@sahal-git make sure you installed PostgreSQL and it's running

adilmohak commented 2 months ago

@sahal-git You're not engaging with this conversation, so I assume the problem is fixed and I will close this issue.

heyeanne34 commented 1 month ago

@sahal-git You're not engaging with this conversation, so I assume the problem is fixed and I will close this issue.

sir same problemi have pgadmin4 created data base named django_lms_data but it still PS C:\Users\LENOVO Z40\django-lms> python manage.py makemigrations Traceback (most recent call last): File "C:\Users\LENOVO Z40\django-lms\manage.py", line 21, in main() File "C:\Users\LENOVO Z40\django-lms\manage.py", line 17, in main execute_from_command_line(sys.argv) File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management__init.py", line 446, in execute_from_command_line utility.execute() File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management__init.py", line 386, in execute settings.INSTALLED_APPS File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\conf__init.py", line 87, in getattr__ self._setup(name) File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\conf__init__.py", line 74, in _setup
self._wrapped = Settings(settings_module) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\conf\
init.py", line 183, in init mod = importlib.import_module(self.SETTINGS_MODULE) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\importlib\init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1204, in _gcd_import File "", line 1176, in _find_and_load File "", line 1147, in _find_and_load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "C:\Users\LENOVO Z40\django-lms\config\settings.py", line 125, in "NAME": config("DB_NAME"), ^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\decouple.py", line 248, in
call return self.config(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\decouple.py", line 107, in call return self.get(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\decouple.py", line 92, in get raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option)) decouple.UndefinedValueError: DB_NAME not found. Declare it as envvar or define a default value. PS C:\Users\LENOVO Z40\django-lms> python manage.py makemigrations Traceback (most recent call last): File "C:\Users\LENOVO Z40\django-lms\manage.py", line 21, in main() File "C:\Users\LENOVO Z40\django-lms\manage.py", line 17, in main execute_from_command_line(sys.argv) File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management__init.py", line 446, in execute_from_command_line utility.execute() File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management__init__.py", line 386, in execute settings.INSTALLED_APPS File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\conf__init.py", line 87, in getattr__ self._setup(name) File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\conf\init__.py", line 74, in _setup
self._wrapped = Settings(settings_module) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\conf\
init.py", line 183, in init mod = importlib.import_module(self.SETTINGS_MODULE) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\importlib\init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1204, in _gcd_import File "", line 1176, in _find_and_load File "", line 1147, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "C:\Users\LENOVO Z40\django-lms\config\settings.py", line 125, in "NAME": config("DB_NAME"), ^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\decouple.py", line 248, in call return self.config(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\decouple.py", line 107, in call__ return self.get(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\decouple.py", line 92, in get raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option)) decouple.UndefinedValueError: DB_NAME not found. Declare it as envvar or define a default value.

aishafatima02 commented 1 month ago

@sahal-git hey I'm facing the same issue, how did you solve it?

adilmohak commented 1 month ago

@sahal-git You're not engaging with this conversation, so I assume the problem is fixed and I will close this issue.

sir same problemi have pgadmin4 created data base named django_lms_data but it still PS C:\Users\LENOVO Z40\django-lms> python manage.py makemigrations Traceback (most recent call last): File "C:\Users\LENOVO Z40\django-lms\manage.py", line 21, in main() File "C:\Users\LENOVO Z40\django-lms\manage.py", line 17, in main execute_from_command_line(sys.argv) File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\managementinit.py", line 446, in execute_from_command_line utility.execute() File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\managementinit.py", line 386, in execute settings.INSTALLED_APPS File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\confinit.py", line 87, in getattr self._setup(name) File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\confinit.py", line 74, in _setup self._wrapped = Settings(settings_module) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\confinit.py", line 183, in init mod = importlib.import_module(self.SETTINGS_MODULE) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\importlibinit.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1204, in _gcd_import File "", line 1176, in _find_and_load File "", line 1147, in _find_and_load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "C:\Users\LENOVO Z40\django-lms\config\settings.py", line 125, in "NAME": config("DB_NAME"), ^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\decouple.py", line 248, in call return self.config(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\decouple.py", line 107, in call return self.get(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\decouple.py", line 92, in get raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option)) decouple.UndefinedValueError: DB_NAME not found. Declare it as envvar or define a default value. PS C:\Users\LENOVO Z40\django-lms> python manage.py makemigrations Traceback (most recent call last): File "C:\Users\LENOVO Z40\django-lms\manage.py", line 21, in main() File "C:\Users\LENOVO Z40\django-lms\manage.py", line 17, in main execute_from_command_line(sys.argv) File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\managementinit.py", line 446, in execute_from_command_line utility.execute() File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\managementinit.py", line 386, in execute settings.INSTALLED_APPS File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\conf_init.py", line 87, in getattr self._setup(name) File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\confinit.py", line 74, in _setup self._wrapped = Settings(settings_module) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\confinit.py", line 183, in init mod = importlib.import_module(self.SETTINGS_MODULE) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\importlibinit.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1204, in _gcd_import File "", line 1176, in _find_and_load File "", line 1147, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "C:\Users\LENOVO Z40\django-lms\config\settings.py", line 125, in "NAME": config("DB_NAME"), ^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\decouple.py", line 248, in call* return self.config(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\decouple.py", line 107, in call return self.get(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\LENOVO Z40\AppData\Local\Programs\Python\Python311\Lib\site-packages\decouple.py", line 92, in get raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option)) decouple.UndefinedValueError: DBNAME not found. Declare it as envvar or define a default value.

It looks like you haven't defined an env variable called DB_NAME. Double-check that your .env file contains all the necessary variables

# Database config
DB_NAME=[YOUR_DB_NAME]
DB_USER=[DB_ADMIN_NAME]
DB_PASSWORD=[DB_ADMIN_PASSWORD]
DB_HOST=localhost
DB_PORT=[YOUR_POSTGRES_PORT default is 5432]

# Email config
EMAIL_FROM_ADDRESS=Django LMS <youremail@example.com>
EMAIL_HOST_USER=[YOUR_EMAIL]
EMAIL_HOST_PASSWORD=[YOUR_EMAIL_PASSWORD]

# Other
DEBUG=True
SECRET_KEY=[YOUR_SECRET_KEY]