I am getting the error
django.db.utils.OperationError: FATAL:database "/path/to/current/project/projectname/databasename" does not exist.
I have accessed the database both manually through psql, as well as through pgadmin4, and have verified in both instances that the database does exist, and I have verified that the port is correct.
Im not sure why I cant access the database, or why it would say the database cannot be found.
According to pgAdmin4, the database is healthy, and it is receiving at least 1 I/O per second, so it can be read and written to by...something?
I have installed both the psycopg2 and the psycopg2-binary just to be safe.
I figured out the answer, or at least I do believe I did. It was a two part problem.
Part of it was I left os.path.join(base_dir...) included as part of the '' name section.
The other was I used an "#" character as part of my password. Once I changed the password, and I removed the os.path.join(base_dir...) portion, it worked.
Related
I'm new to Flask and web development in general. I have a Flask web-application that is using SQLAlchemy, is it ok to put session.rollback at the beginning of the app in order to keep it running even after a transaction fails?
I had a problem with my website when it stopped working after I was attempting to delete records of one table. The error log showed that the deletion failed due to entries in another table still referencing these records as their foreign key. The error log suggested using session.rollback to rollback this change, so I put it at the beginning of my app just after binding my database and creating the session and my website worked. This gave me the hint to leave that line there. Is my move right, safe and ok? Can anyone tell me what is the correct thing to do if this is somewhat endangering the functionality or logic of my website by any chance?
I'd say by that you are by definition cargo cult coding and should try to determine why you're finding these errors in the first place instead of just including a bit of code for a reason you don't understand.
The problem you're describing is the result of using foreign keys to ensure data integrity in your database. Typically SQLAlchemy will nullify all of the depending foreign keys, but since I don't know anything about your set up I can't explain why it wasn't. It is perhaps a difference between databases.
One massive problem with putting the rollback at the beginning of a route (or the entire global app) is that you might rollback data which you didn't want to. You haven't provided an MVCE so no one can really help you debug your problem.
Cargo cult coding in circumstances like this is understandable, but it's never a good practice. To solve this problem, investigate the cascades in SQLAlchemy. Also, fire up your actual SQL db interface and look at the data's structure, and set SQLALCHEMY_ECHO = 1 in your config file to see what's actually getting emitted.
Good luck!
You should not use the rollback at the beginning but when a database operation fails.
The error is due to an integrity condition in your database. Some rows in your table are being referenced by another table. So, you have to remove referencing rows first.
I'm working on a script to automate a file load procedure. So, naturally I need to perform some stored procedures that already exist. I'm using pyodbc to connect to my database. I can SELECT perfectly fine from the database, but when I try to execute from the database I get this error:
pyodbc.ProgrammingError: ('42000', '[42000] [Microsoft][SQL Server Native Client 10.0]
Syntax error, permission violation, or other nonspecific error (0) (SQLExecDirectW)')
I can't figure out what the problem here is - the user has full DB admin permissions, the syntax is correct based off what the pyodbc official documentation says.
print("Executing SP")
conn.execute('{EXEC TEMP.s_p_test}')
print("SP Executed.")
Here, TEMP is the schema for the type of stored procedure in that specific database. I.e., it's the full name of the stored procedure. I feel like it's probably something stupidly obvious that I'm just missing.
I tried a couple of things to fix it. As #Brian Pendleton suggested, I had tried to change from an explicit database user defined via UID and PWD to trusted_connection=True. Unfortunately that did not change anything.
However, out of curiosity I decided to see what taking the curly braces out of the function call would do. The execution worked immediately and produced the desired output. It would seem that the documentation at pyodbc's wiki either shows bad examples or I found a bug I don't know how to replicate because I don't know what makes my situation abnormal.
Or, in other words, instead of
conn.execute('{EXEC TEMP.s_p_test}')
I used
conn.execute('EXEC TEMP.s_p_test')
I am using Django for an application that uses a simple filtering system. I want the filter to test if the title of my model contains a query string.
The code, stripped down, looks like this:
cards = Card.objects.filter(title__icontains=query)
print cards.query
which returns the following query (again, unnecessary stuff is stripped):
SELECT [...] FROM `ygo_card_card`
WHERE `ygo_card_card`.`title` LIKE %dark%
Which returns no results, even though it should. When I run this query manually, I get
SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%dark%' at line 1
If I wrap the %dark% part between apostrophes ('%dark%') when running manually, it works as expected. It seems to me that Django creates an incorrect query. Is this a bug or something that I can control by settings?
Any search returns irrelevant results, because the related keywords are too generic.
I use Django 1.6.5 and MySQL 5.5.38, running on Ubuntu Server 14.04 LTS.
The response is quite simple: I misinterpreted the problem.
The issue comes from an underlying problem: the MySQL LIKE statement is case-sensitive or insensitive depending on the collation and the Django filter used (icontains or contains) has no effect in the outcome. You can see this bug ticket for more information.
As Daniel Roseman pointed out, the .query property is not reliable, as the query is further processed by the database driver. This led me to believe that Django created a wrong query, while in fact it simply created a case-sensitive search that should have been case-insensitive, hence the lack of results.
In the end, the issue was resolved by changing the collation on columns, tables and the database.
I actually found a blog post that pretty much sums up my problem. Its at
http://simon04.net/2013/03/python3-mysql/
The blog post is the most clear but to summarize: I'm currently trying to access a remote MySQL database with a python package called PyMySQL3. However I keep getting the error: "AttributeError: 'bytes' object has no attribute 'encode'". From the blog post above and some other research, I think this has to do with my database having an old authentication method.
However, I'm confused because it looks like the old authentication method was phased out sometime in MySQL 4.0. The database I have runs MySQL 5.0.51a. Shouldn't my database have the correct authentication?
I've been working on this awhile and getting a little frustrated. Hopefully someone can help. Thanks,
From https://github.com/petehunt/PyMySQL/issues/64
For me this problem was due to the usage of the old authentication
method (cf.
http://dev.mysql.com/doc/internals/en/authentication-method.html).
Creating a new user (resetting the password might work as well) and
making sure that the password column for this user in the mysql.user
table starts with a * (otherwise check the server configuration
according to the above link), solved the problem for me.
Have you created the users with this very Version you mentioned?
The thread shows how to fix the problem in the code aswell, tellme when you need additional help to fix it. I would edit my answer accordingly.
Ok, while investigating this more I thought that maybe my hosting company (aplus.net) just wasn't up to date. I was going to switch companies anyways and so I opened a new account with another company. Now I have no problems connecting with PyMySQL3. So apparently, my old hosting company just wasn't up to date or at least their sql configuration was breaking PyMySQL3.
Thanks for your reponse though. Hopefully not many other people have this issue because switching hosting companies isn't always the best answer =O
I am in the process of trying to upgrade my module written for Openerp. Although it works fine on the local machine and the local openerp server. It gives me the below error when I try to update the files via SVN to the staged server. The error states that they are trying to insert a record to the DB where is its actually an update not a insertion. I am worried to remove that record from the Postgres db directly though, i think it might do the trick.
I also removed all the existing files before I did the SVN update on the staged server. May be this might have been the pit fall but i am not quite sure. Let me know what you guys think is the best solution for this problem. Below is the error messages show in Openerp Server when its restarted after the SVN update. The Server Stops from here and never ends.
But soon as I revert the files or remove them and update the Server works like a Charm.
module abc: loading objects
[2011-09-14 08:12:49,425][oe_test] INFO:init:module abc:registering objects
[2011-09-14 08:12:49,432][oe_test] INFO:init:module abc: creating or updating database tables
[2011-09-14 08:12:49,434][oe_test] DEBUG:sql:bad query: INSERT INTO ir_model_data (name,date_init,date_update,module,model,res_id) VALUES (E'model_abc', now(), now(), E'abc', E'ir.model', 301)
[2011-09-14 08:12:49,434][oe_test] DEBUG:sql:('model_abc', u'abc', 'ir.model', 301)
[2011-09-14 08:12:49,434][oe_test] DEBUG:sql:duplicate key value violates unique constraint "ir_model_data_module_name_uniq"
Regards,
Gayan
[2011-09-14 08:12:49,434][oe_test] DEBUG:sql:duplicate key value violates unique constraint "ir_model_data_module_name_uniq"
In ir.model.data, there is an "_sql_constraint", defined for unique record name. so error comes from that code and says that You can't have duplicate record name.
as per my knowledge, this kind of error could occur, because of duplicate record id in your *_data.xml file.
Note : Check either noupdate="True" in your *_data.xml file or not.
After running around with the above problem I was able to figure out the actual cause and over come the issue. The underling problem was that I have another module which accidentally carries the same name. So due to this the above conflicting exception occurs. Finally I changed the module name, and the model names and the problem was sorted.
Thanks for all the inputs.
Regards,
Gayan
did you try to launch the server with -u your_module_name -d your_db_name?