Tag Archives: django

Django. DB. Utils. Programmingerror: (1146, “table * doesn’t exist”) causes and Solutions

Reason 1:

In the record file generated by each change in the migrations folder in the app, there are operations to delete a table or delete a field, but these modifications are generated in someone else’s environment. When running in your own environment for the first time, you will run the deletion operation first when Python manage. Py migrate , At this time, an error will be reported Django. DB. Utils. Programmingerror: (1146, "table 'doesn't exist")

Reason 2:

The table was called first in the urls.py file.

EnvironmentError:mysql config not found

MySQL for Python Library in Python is equivalent to the jdbc driver corresponding to MySQL in Java

1. Install MySQL first

sudo apt-get install mysql-server

 

2. Install MySQL Python

Download mysql-python-1.2.3.tar.gz (see the attachment) and unzip it to the specified directory.

Compile and configure MySQL Python in the decompressed mysql-python-1.2.3 directory

python setup.py build

At this time, the system reports an error: environmenterror: MySQL_ config not found

Obviously there is no mysql_ Configure this file

Execute find/- name MySQL_ Config, there is no data, indicating that there is no MySQL in the system_ Configure this file

 

 

Someone on the Internet explained that MySQL installed with apt get does not have mysql_ Config is the name of this file

Solution:

(1) Ubuntu next

Execute sudo apt get install libmysqld dev

(2) Fedora next

Execute sudo Yum install Python devel

If it appears: my_ Config. H: without that file or directory, execute: sudo Yum install MySQL devel

Note: Yum is also written in Python, and/usr/bin/Python is called by default. This is the python that comes with the system itself. You can install it in/usr/local/bin/python, so you’d better not uninstall the python that comes with the system. The python you download doesn’t have the yum module.

 

Execute at this time   find/-name mysql_ Config found this file under/usr/bin /

Then modify the site.cfg file in the mysql-python-1.2.3 directory

Remove MySQL_ Config = XXX and change to MySQL_ config=/usr/bin/mysql_ Config (in MySQL)_ The directory on the machine where the config file is located shall prevail.)

Execute the following command to compile and install successfully:

python setup.py build

python setup.py install

http://zhoujianghai.iteye.com/blog/1520666

[Solved] UnicodeEncodeError: ‘ascii‘ codec can‘t encode characters in position 3-9: ordinal not in range(128)

linux django UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 36-45: ordinal not in range(128)
error:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 36-45: ordinal not in range(128)

Solution:

vi ~/.bashrc
export LC_ALL=C.UTF-8
source ~/.bashrc

How to solve the problem of error reporting in the introduction of Python Django no module name ‘Django. Utils. Six’

Today, when learning Django framework, I wrote the following command:

from django.utils.six import BytesIO

After that, an error is reported as follows:

I looked up the relevant documents, various, did not come to the point.

In fact, the root of this problem is very easy to understand: there may be no such file as six. Py under the path of Django/utils /!!

Taking this machine as an example, I first checked the following path. There is no file “six. Py”.

Next, I chose to use the command line:

pip install six

But the previous command still runs and reports an error, although the six. Py has been downloaded.

At this time, you need to go to your PIP folder and find the file “six. Py”

Then copy the file and paste it under the path of Django/utils

At this point, rerun the command

from django.utils.six import BytesIO

After running successfully, no error is reported

It’s done!!

[Solved] Django Access to the backend error: Invalid block tag on line 98: ‘trans‘, expected ‘elif , ‘else‘或‘ endif. Did you forget

Error:
django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 98: ‘translate’, expected ‘elif’, ‘else’ or ‘endif’. Did you forget to register or load this tag?

Solution:

Find the the catalog in the error message and then delete the red codes.

Save the file and solve it.

[Solved] from django.core.cache import cache Error

Import from django.core.cache import cache
Error:

django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Solution:

from django.conf import settings
settings.configure(DEBUG=True)

Done!

 

 

[Solved] AttributeError: ‘Manager‘ object has no attribute ‘get_by_natural_key‘

Problem description


E:\SweetYaya\MyProj03>python manage.py createsuperuser
Identifier: 12
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "D:\Program Files\Python36\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "D:\Program Files\Python36\lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\Program Files\Python36\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "D:\Program Files\Python36\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 79, in execute
    return super().execute(*args, **options)
  File "D:\Program Files\Python36\lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "D:\Program Files\Python36\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 113, in handle
    error_msg = self._validate_username(username, verbose_field_name, database)
  File "D:\Program Files\Python36\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 234, in _validate_username
    self.UserModel._default_manager.db_manager(database).get_by_natural_key(username)
AttributeError: 'Manager' object has no attribute 'get_by_natural_key'

terms of settlement


Add to the defined model

class SysUsers(models.Model):
    
	...
	# add
    objects = UserManager()
	
	...

Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools“

Alipay’s online payment function has recently been developed to download and pay the SDK package. The wrong presentation is as follows:
reported false prompts: Microsoft Visual C++ 14 or greater is required. Get it it ” https://visualstudio.microsoft.com/visual-cpp-build-tools/

Reason: python3 is compiled with VC + + 14, python27 is compiled with C + + 9, and the package to install python3 needs to be compiled with C + + 14 or above

Don’t panic for small scenes

That’s the thing above. Double click the installation. Do you think it’s over?

In case of no accident, most of the installation packages you download will finally prompt you: the installation package is missing or damaged
some netizens say that it can succeed with a ladder, and others say that it can’t succeed
I uploaded an offline version here. You can try

django.db.utils.OperationalError: no such table: django_admin_log

Problem orientation


Using Python shell to delete custom user table data

from MyApp import models
dU = models.SysUsers.objects.all()
dU.delete()

The error is as follows

django.db.utils.OperationalError: no such table: django_admin_log

terms of settlement


Direct migrate may not work. Parameters should be added as follows

python manage.py makemigrations
python manage.py migrate --run-syncdb

ValueError: The field admin.LogEntry.user was declared with a lazy reference to ‘MyApp.sysusers‘

Problem description


E:\SweetYaya\MyProj03>python manage.py migrate
Operations to perform:
  Apply all migrations: MyApp, admin, auth, contenttypes, sessions
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "D:\Program Files\Python36\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "D:\Program Files\Python36\lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\Program Files\Python36\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "D:\Program Files\Python36\lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "D:\Program Files\Python36\lib\site-packages\django\core\management\base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "D:\Program Files\Python36\lib\site-packages\django\core\management\commands\migrate.py", line 202, in handle
    pre_migrate_apps = pre_migrate_state.apps
  File "D:\Program Files\Python36\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\Program Files\Python36\lib\site-packages\django\db\migrations\state.py", line 208, in apps
    return StateApps(self.real_apps, self.models)
  File "D:\Program Files\Python36\lib\site-packages\django\db\migrations\state.py", line 277, in __init__
    raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'MyApp.sysuser', but app 'MyApp' doesn't provide model 'sysuser'.

Find your own python3. X and enter the site packages/Django/contrib/admin/migrations file directory__ init__. Py file, delete all others( Be careful not to__ init__. If you delete the PY file, don’t delete the migrations in the folder contrib/contenttypes. Otherwise, the function of migrate will be invalid and Django can only be removed.