I am on it now. I see a lot to read
Here is the latest situation;
I used both setting pythnutf8 as environment variable and’’ python -X utf8 manage.py runserver"
I deleted virtual env and recreated and pip instal requirements.txt
Yet this error persists. So ı am considering deleting Python and reinstalling again.
I also now deleted the DB and deployed a new one. I haven’t tried it with its password but not sure it is the issiue.
Will be trying to update after Python re-installation.
Here comes update. I deleted python all together then installed again. But to no result.
I will sacrifice my first born ı think to figure this out
Again an update! I sit down and write down an automation script to check if any .py file was not UTF-8 encoded. The list was long and result all seems to be encoded UTF-8 but still when ı go to Postgres DB it is still raising the same error.
Any body needs an automation script to check for UTF-8 encoding here be my guest! At this point ı do not know anymore. Anybody has an idea please do let me know. I am not sure why this error is coming. I will dtry using mysql tomorrow to see.
import os
def check_utf8_encoding(file_path):
try:
with open(file_path, 'r', encoding='utf-8') as file:
file.read()
return True
except UnicodeDecodeError:
return False
def check_directory_for_python_files(directory):
for root, _, files in os.walk(directory):
for file in files:
if file.endswith('.py'):
file_path = os.path.join(root, file)
is_utf8 = check_utf8_encoding(file_path)
print(f"{file_path}: {'UTF-8 encoded' if is_utf8 else 'Not UTF-8 encoded'}")
# Replace this with the directory you want to check
directory_to_check = r"C:/Users/cetin/OneDrive/Masaüstü/ecom"
check_directory_for_python_files(directory_to_check)
May I suggest trying something from a different direction?
Try creating a new project from scratch using the django-admin startproject
command. Then, replace the DATABASES
setting with your postgres setting. Then, try migrate
. Don’t do anything else. Don’t bring in any extra code, don’t make any other settings changes.
ı just did that sir and exactly same error comes up. Again ı go back sqlite it just works but when ı add postgres info no it does not.
I created a new project with name ‘ecomm’ in a directory called test
Traceback (most recent call last):
File "C:\Users\cetin\OneDrive\Masaüstü\Test\ecomm\manage.py", line 22, in <module>
main()
File "C:\Users\cetin\OneDrive\Masaüstü\Test\ecomm\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\core\management\__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\core\management\base.py", line 413, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\core\management\base.py", line 459, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\core\management\base.py", line 107, in wrapper
res = handle_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\core\management\commands\migrate.py", line 118, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\db\migrations\loader.py", line 58, in __init__
self.build_graph()
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\db\migrations\loader.py", line 235, in build_graph
self.applied_migrations = recorder.applied_migrations()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\db\migrations\recorder.py", line 89, in applied_migrations
if self.has_table():
^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\db\migrations\recorder.py", line 63, in has_table
with self.connection.cursor() as cursor:
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\db\backends\base\base.py", line 320, in cursor
return self._cursor()
^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\db\backends\base\base.py", line 296, in _cursor
self.ensure_connection()
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\db\backends\base\base.py", line 279, in ensure_connection
self.connect()
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\db\backends\base\base.py", line 256, in connect
self.connection = self.get_new_connection(conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\django\db\backends\postgresql\base.py", line 350, in get_new_connection
connection = self.Database.connect(**conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\Test\virt\Lib\site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf6 in position 79: invalid start byte
In answering another question, I came up with another thought.
What are you using as your editor / IDE for working with these files?
VScode sir. Somebody from django discord pointed out ı should try changing my Masaüstü(in Turkish means Desktop. Person said that might be issiue but ı do not think so)
A quick update!
I do not know what happend. I am not sure what changed or ı am not sure what ı did but now the error changed . Now ı am more focusing on to raiway service. And ı will try to get in touch with them as well so maybe they know. I made bold now for the new error you can see!
File "C:\Users\cetin\OneDrive\Masaüstü\ecom\virt\Lib\site-packages\django\db\backends\base\base.py", line 256, in connect
self.connection = self.get_new_connection(conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\ecom\virt\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\ecom\virt\Lib\site-packages\django\db\backends\postgresql\base.py", line 350, in get_new_connection
connection = self.Database.connect(**conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\cetin\OneDrive\Masaüstü\ecom\virt\Lib\site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**django.db.utils.OperationalError: could not translate host name "postgres.railway.internal" to address: No such host is known.**
Update;
I solved the case. I am not fully aware how things works but seems like problem arised because of railway having two version(I cannot think better word) of private and public network for DB and to create the first connection before web-hosting one must use the public(note: They default provide a private and there is no reference to such a difference exist. So there were no posibility for me to understand that.) I learned that after a friend of mine suggested me to contact railway and ask them the issiue as well . They responded 3 days later and told me that ı have to go for some settings and find public network and get the db settings from the first and when ı do launch then ı change it to private. Don ask me why and how. That is what they told me to do and ı did it. Then voila! suddenly ı connect. Of course all tables and data is gone.(I believe could be expected but ı am curious if it persists if ı go back to sqlite). All users even superuser is gone as well. I am not sure if ı can create superuser with same info again but ı am too tired to check now.
So yea! Thank you for your time and support :):):)